|
@@ -1,8 +1,12 @@
|
|
|
package cn.com.qmth.examcloud.web.helpers;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.assertj.core.util.Arrays;
|
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+
|
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
|
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
|
|
|
import cn.com.qmth.examcloud.commons.util.ThreadLocalUtil;
|
|
@@ -50,8 +54,15 @@ public class SequenceLockHelper {
|
|
|
if (LOG.isDebugEnabled()) {
|
|
|
LOG.debug("locked");
|
|
|
}
|
|
|
- ServletUtil.getRequest()
|
|
|
- .setAttribute(HttpServletRequestAttribute.$_CUSTOM_SEQUENCE_LOCK.name(), key);
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ List<String> keyList = (List<String>) ServletUtil.getRequest()
|
|
|
+ .getAttribute(HttpServletRequestAttribute.$_CUSTOM_SEQUENCE_LOCK.name());
|
|
|
+ if (null == keyList) {
|
|
|
+ keyList = Lists.newArrayList();
|
|
|
+ }
|
|
|
+ keyList.add(key);
|
|
|
+ ServletUtil.getRequest().setAttribute(
|
|
|
+ HttpServletRequestAttribute.$_CUSTOM_SEQUENCE_LOCK.name(), keyList);
|
|
|
} else {
|
|
|
throw new SequenceLockException("请求等待,请稍后重试!");
|
|
|
}
|
|
@@ -66,8 +77,14 @@ public class SequenceLockHelper {
|
|
|
public static void releaseLock(Object... args) {
|
|
|
String key = LOCK_PREFIX + StringUtils.join(Arrays.asList(args), "_");
|
|
|
getRedisClient().delete(key);
|
|
|
- ServletUtil.getRequest()
|
|
|
- .removeAttribute(HttpServletRequestAttribute.$_CUSTOM_SEQUENCE_LOCK.name());
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ List<String> keyList = (List<String>) ServletUtil.getRequest()
|
|
|
+ .getAttribute(HttpServletRequestAttribute.$_CUSTOM_SEQUENCE_LOCK.name());
|
|
|
+ if (null != keyList) {
|
|
|
+ if (keyList.contains(key)) {
|
|
|
+ keyList.remove(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|