Commit 09b61120 authored by yanzg's avatar yanzg

异常处理显示

parent cf8775c6
...@@ -6,7 +6,6 @@ import com.yanzuoguang.token.TokenLoad; ...@@ -6,7 +6,6 @@ import com.yanzuoguang.token.TokenLoad;
import com.yanzuoguang.util.cache.MemoryCache; import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log; import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.thread.ThreadHelper;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -26,7 +25,7 @@ public class TokenServiceCall implements TokenLoad { ...@@ -26,7 +25,7 @@ public class TokenServiceCall implements TokenLoad {
private int flagCount = 3; private int flagCount = 3;
private MemoryCache<Boolean> countCache = new MemoryCache<>(); private MemoryCache<Integer> countCache = new MemoryCache<>();
public TokenServiceCall() { public TokenServiceCall() {
TokenHelper.setTokenLoad(this); TokenHelper.setTokenLoad(this);
...@@ -53,14 +52,14 @@ public class TokenServiceCall implements TokenLoad { ...@@ -53,14 +52,14 @@ public class TokenServiceCall implements TokenLoad {
*/ */
public boolean tokenInit() { public boolean tokenInit() {
init(); init();
addHave();
if (tokenService == null) { if (tokenService == null) {
return false; return false;
} }
if (isHave()) { if (addHave(0) == 1) {
return false; return false;
} }
tokenService.tokenInit(); tokenService.tokenInit();
setHave();
return true; return true;
} }
...@@ -69,11 +68,13 @@ public class TokenServiceCall implements TokenLoad { ...@@ -69,11 +68,13 @@ public class TokenServiceCall implements TokenLoad {
*/ */
public void tokenFinish() { public void tokenFinish() {
init(); init();
subHave();
if (tokenService == null) { if (tokenService == null) {
return; return;
} }
tokenService.tokenFinish(); if (addHave(0) == 0) {
removeHave(); tokenService.tokenFinish();
}
} }
/** /**
...@@ -91,18 +92,19 @@ public class TokenServiceCall implements TokenLoad { ...@@ -91,18 +92,19 @@ public class TokenServiceCall implements TokenLoad {
return tokenService.load(token); return tokenService.load(token);
} }
private boolean isHave() { private int addHave(int flag) {
String id = StringHelper.toString(Thread.currentThread().getId()); String id = StringHelper.toString(Thread.currentThread().getId());
return StringHelper.toBoolean(countCache.get(id)); int from = StringHelper.toInt(countCache.get(id));
int to = from + flag;
countCache.put(id, to);
return to;
} }
private void setHave() { private int addHave() {
String id = StringHelper.toString(Thread.currentThread().getId()); return addHave(1);
countCache.put(id, true);
} }
private void removeHave() { private int subHave() {
String id = StringHelper.toString(Thread.currentThread().getId()); return addHave(-1);
countCache.remove(id);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment