浏览代码

优化锁

WANG 5 年之前
父节点
当前提交
b481758e4c

+ 12 - 0
src/main/java/cn/com/qmth/examcloud/web/interceptor/SeqlockInterceptor.java

@@ -1,10 +1,12 @@
 package cn.com.qmth.examcloud.web.interceptor;
 
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.collections.CollectionUtils;
 import org.springframework.http.HttpStatus;
 import org.springframework.web.method.HandlerMethod;
 import org.springframework.web.servlet.HandlerInterceptor;
@@ -123,6 +125,16 @@ public class SeqlockInterceptor implements HandlerInterceptor {
 		if (null != key) {
 			redisClient.expire((String) key, 100, TimeUnit.MILLISECONDS);
 		}
+
+		@SuppressWarnings("unchecked")
+		List<String> keyList = (List<String>) ServletUtil.getRequest()
+				.getAttribute(HttpServletRequestAttribute.$_CUSTOM_SEQUENCE_LOCK.name());
+		if (CollectionUtils.isNotEmpty(keyList)) {
+			for (String cur : keyList) {
+				redisClient.delete(cur);
+			}
+		}
+
 	}
 
 }

+ 0 - 14
src/main/java/cn/com/qmth/examcloud/web/support/ControllerAspect.java

@@ -1,14 +1,11 @@
 package cn.com.qmth.examcloud.web.support;
 
 import java.util.Collection;
-import java.util.List;
 import java.util.Map;
-import java.util.concurrent.TimeUnit;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.commons.collections.CollectionUtils;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Aspect;
@@ -158,17 +155,6 @@ public class ControllerAspect {
 			INTERFACE_LOG.error(StringUtil.join("[HTTP-FAIL]. path=\"", path, "\", method=[",
 					method, "] ; cost ", System.currentTimeMillis() - startTime, " ms."));
 			throw new RuntimeException(e);
-		} finally {
-			if (null != redisClient && redisClient.isEnable()) {
-				@SuppressWarnings("unchecked")
-				List<String> keyList = (List<String>) ServletUtil.getRequest()
-						.getAttribute(HttpServletRequestAttribute.$_CUSTOM_SEQUENCE_LOCK.name());
-				if (CollectionUtils.isNotEmpty(keyList)) {
-					for (String key : keyList) {
-						redisClient.expire((String) key, 100, TimeUnit.MILLISECONDS);
-					}
-				}
-			}
 		}
 
 		if (null != httpMethodProcessor) {