Skip to content

Commit 8c80ca2

Browse files
committed
modify
1 parent 01cee5a commit 8c80ca2

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/WxMsgIdInMemoryDuplicateChecker.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ public class WxMsgIdInMemoryDuplicateChecker implements WxMsgIdDuplicateChecker
1414
/**
1515
* 一个消息ID在内存的过期时间:15秒
1616
*/
17-
private final Long TIME_TO_LIVE;
17+
private final Long timeToLive;
1818

1919
/**
2020
* 每隔多少周期检查消息ID是否过期:5秒
2121
*/
22-
private final Long CLEAR_PERIOD;
22+
private final Long clearPeriod;
2323

2424
private final ConcurrentHashMap<Long, Long> msgId2Timestamp = new ConcurrentHashMap<Long, Long>();
2525

@@ -31,8 +31,8 @@ public class WxMsgIdInMemoryDuplicateChecker implements WxMsgIdDuplicateChecker
3131
* </pre>
3232
*/
3333
public WxMsgIdInMemoryDuplicateChecker() {
34-
this.TIME_TO_LIVE = 15 * 1000l;
35-
this.CLEAR_PERIOD = 5 * 1000l;
34+
this.timeToLive = 15 * 1000l;
35+
this.clearPeriod = 5 * 1000l;
3636
this.start();
3737
}
3838

@@ -42,8 +42,8 @@ public WxMsgIdInMemoryDuplicateChecker() {
4242
* @param clearPeriod 每隔多少周期检查消息ID是否过期:毫秒
4343
*/
4444
public WxMsgIdInMemoryDuplicateChecker(Long timeToLive, Long clearPeriod) {
45-
this.TIME_TO_LIVE = timeToLive;
46-
this.CLEAR_PERIOD = clearPeriod;
45+
this.timeToLive = timeToLive;
46+
this.clearPeriod = clearPeriod;
4747
this.start();
4848
}
4949

@@ -53,10 +53,10 @@ private void start() {
5353
public void run() {
5454
try {
5555
while (true) {
56-
Thread.sleep(CLEAR_PERIOD);
56+
Thread.sleep(clearPeriod);
5757
Long now = System.currentTimeMillis();
5858
for (Map.Entry<Long, Long> entry : msgId2Timestamp.entrySet()) {
59-
if (now - entry.getValue() > TIME_TO_LIVE) {
59+
if (now - entry.getValue() > timeToLive) {
6060
msgId2Timestamp.entrySet().remove(entry);
6161
}
6262
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,18 @@
3939
import java.security.NoSuchAlgorithmException;
4040
import java.util.List;
4141
import java.util.UUID;
42-
import java.util.concurrent.atomic.AtomicBoolean;
4342

4443
public class WxMpServiceImpl implements WxMpService {
4544

4645
/**
4746
* 全局的是否正在刷新access token的锁
4847
*/
49-
protected static final Object GLOBAL_ACCESS_TOKEN_REFRESH_LOCK = new Object();
48+
protected final Object globalAccessTokenRefreshLock = new Object();
5049

5150
/**
5251
* 全局的是否正在刷新jsapi_ticket的锁
5352
*/
54-
protected static final Object GLOBAL_JSAPI_TICKET_REFRESH_LOCK = new Object();
53+
protected final Object globalJsapiTicketRefreshLock = new Object();
5554

5655
protected WxMpConfigStorage wxMpConfigStorage;
5756

@@ -78,7 +77,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
7877
wxMpConfigStorage.expireAccessToken();
7978
}
8079
if (wxMpConfigStorage.isAccessTokenExpired()) {
81-
synchronized (GLOBAL_ACCESS_TOKEN_REFRESH_LOCK) {
80+
synchronized (globalAccessTokenRefreshLock) {
8281
if (wxMpConfigStorage.isAccessTokenExpired()) {
8382
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential"
8483
+ "&appid=" + wxMpConfigStorage.getAppId()
@@ -119,7 +118,7 @@ public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
119118
wxMpConfigStorage.expireJsapiTicket();
120119
}
121120
if (wxMpConfigStorage.isJsapiTicketExpired()) {
122-
synchronized (GLOBAL_JSAPI_TICKET_REFRESH_LOCK) {
121+
synchronized (globalJsapiTicketRefreshLock) {
123122
if (wxMpConfigStorage.isJsapiTicketExpired()) {
124123
String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi";
125124
String responseContent = execute(new SimpleGetRequestExecutor(), url, null);

0 commit comments

Comments
 (0)