Skip to content

Commit fc8d815

Browse files
authored
🎨 增加加锁的超时时间,避免死循环
1 parent ad6ad00 commit fc8d815

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,17 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
263263
}
264264

265265
Lock lock = this.getWxMpConfigStorage().getAccessTokenLock();
266+
long timeOutMillis = System.currentTimeMillis() + 3000;
266267
boolean locked = false;
267268
try {
268269
do {
269270
locked = lock.tryLock(100, TimeUnit.MILLISECONDS);
270271
if (!forceRefresh && !this.getWxMpConfigStorage().isAccessTokenExpired()) {
271272
return this.getWxMpConfigStorage().getAccessToken();
272273
}
274+
if (!locked && System.currentTimeMillis() > timeOutMillis) {
275+
throw new InterruptedException("获取accessToken超时:获取时间超时");
276+
}
273277
} while (!locked);
274278

275279
String response;

0 commit comments

Comments
 (0)