|
@@ -35,10 +35,7 @@ public class MarkLockService {
|
|
* @param group
|
|
* @param group
|
|
*/
|
|
*/
|
|
public void lockGroup(Integer examId, String subjectCode, Integer groupNumber) {
|
|
public void lockGroup(Integer examId, String subjectCode, Integer groupNumber) {
|
|
- AtomicBoolean lock = getLock(groupMap, getKey(examId, subjectCode, groupNumber));
|
|
|
|
- while (!lock.get()) {
|
|
|
|
- lock.compareAndSet(false, true);
|
|
|
|
- }
|
|
|
|
|
|
+ lock(getLock(groupMap, getKey(examId, subjectCode, groupNumber)));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -47,10 +44,7 @@ public class MarkLockService {
|
|
* @param group
|
|
* @param group
|
|
*/
|
|
*/
|
|
public void unlockGroup(Integer examId, String subjectCode, Integer groupNumber) {
|
|
public void unlockGroup(Integer examId, String subjectCode, Integer groupNumber) {
|
|
- AtomicBoolean lock = getLock(groupMap, getKey(examId, subjectCode, groupNumber));
|
|
|
|
- while (lock != null && lock.get()) {
|
|
|
|
- lock.compareAndSet(true, false);
|
|
|
|
- }
|
|
|
|
|
|
+ unlock(getLock(groupMap, getKey(examId, subjectCode, groupNumber)));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -59,10 +53,7 @@ public class MarkLockService {
|
|
* @param group
|
|
* @param group
|
|
*/
|
|
*/
|
|
public void waitUnlockGroup(Integer examId, String subjectCode, Integer groupNumber) {
|
|
public void waitUnlockGroup(Integer examId, String subjectCode, Integer groupNumber) {
|
|
- AtomicBoolean lock = getLock(groupMap, getKey(examId, subjectCode, groupNumber));
|
|
|
|
- while (lock.get()) {
|
|
|
|
- ;
|
|
|
|
- }
|
|
|
|
|
|
+ waitUnlock(getLock(groupMap, getKey(examId, subjectCode, groupNumber)));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -71,10 +62,7 @@ public class MarkLockService {
|
|
* @param studentId
|
|
* @param studentId
|
|
*/
|
|
*/
|
|
public void lockStudent(Integer studentId) {
|
|
public void lockStudent(Integer studentId) {
|
|
- AtomicBoolean lock = getLock(studentMap, studentId);
|
|
|
|
- while (!lock.get()) {
|
|
|
|
- lock.compareAndSet(false, true);
|
|
|
|
- }
|
|
|
|
|
|
+ lock(getLock(studentMap, studentId));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -83,10 +71,7 @@ public class MarkLockService {
|
|
* @param studentId
|
|
* @param studentId
|
|
*/
|
|
*/
|
|
public void unlockStudent(Integer studentId) {
|
|
public void unlockStudent(Integer studentId) {
|
|
- AtomicBoolean lock = getLock(studentMap, studentId);
|
|
|
|
- while (lock.get()) {
|
|
|
|
- lock.compareAndSet(true, false);
|
|
|
|
- }
|
|
|
|
|
|
+ unlock(getLock(studentMap, studentId));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -95,10 +80,7 @@ public class MarkLockService {
|
|
* @param studentId
|
|
* @param studentId
|
|
*/
|
|
*/
|
|
public void waitUnlockStudent(Integer studentId) {
|
|
public void waitUnlockStudent(Integer studentId) {
|
|
- AtomicBoolean lock = getLock(studentMap, studentId);
|
|
|
|
- while (lock.get()) {
|
|
|
|
- ;
|
|
|
|
- }
|
|
|
|
|
|
+ waitUnlock(getLock(studentMap, studentId));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -107,10 +89,7 @@ public class MarkLockService {
|
|
* @param markerId
|
|
* @param markerId
|
|
*/
|
|
*/
|
|
public void lockMarker(Integer markerId) {
|
|
public void lockMarker(Integer markerId) {
|
|
- AtomicBoolean lock = getLock(markerMap, markerId);
|
|
|
|
- while (!lock.get()) {
|
|
|
|
- lock.compareAndSet(false, true);
|
|
|
|
- }
|
|
|
|
|
|
+ lock(getLock(markerMap, markerId));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -119,10 +98,7 @@ public class MarkLockService {
|
|
* @param markerId
|
|
* @param markerId
|
|
*/
|
|
*/
|
|
public void unlockMarker(Integer markerId) {
|
|
public void unlockMarker(Integer markerId) {
|
|
- AtomicBoolean lock = getLock(markerMap, markerId);
|
|
|
|
- while (lock.get()) {
|
|
|
|
- lock.compareAndSet(true, false);
|
|
|
|
- }
|
|
|
|
|
|
+ unlock(getLock(markerMap, markerId));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -131,10 +107,7 @@ public class MarkLockService {
|
|
* @param studentId
|
|
* @param studentId
|
|
*/
|
|
*/
|
|
public void waitUnlockMarker(Integer markerId) {
|
|
public void waitUnlockMarker(Integer markerId) {
|
|
- AtomicBoolean lock = getLock(markerMap, markerId);
|
|
|
|
- while (lock.get()) {
|
|
|
|
- ;
|
|
|
|
- }
|
|
|
|
|
|
+ waitUnlock(getLock(markerMap, markerId));
|
|
}
|
|
}
|
|
|
|
|
|
public void clear() {
|
|
public void clear() {
|
|
@@ -179,4 +152,28 @@ public class MarkLockService {
|
|
return examId + "_" + subjectCode + "_" + groupNumber;
|
|
return examId + "_" + subjectCode + "_" + groupNumber;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void lock(AtomicBoolean lock) {
|
|
|
|
+ while (true) {
|
|
|
|
+ if (lock.compareAndSet(false, true)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void unlock(AtomicBoolean lock) {
|
|
|
|
+ while (true) {
|
|
|
|
+ if (lock.compareAndSet(true, false)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void waitUnlock(AtomicBoolean lock) {
|
|
|
|
+ while (true) {
|
|
|
|
+ if (!lock.get()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|