Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lkqm committed May 12, 2020
1 parent 92ea01e commit 1e29d39
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import lombok.Data;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.enums.TicketType;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.mp.bean.WxMpHostConfig;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.common.enums.TicketType;
import me.chanjar.weixin.open.api.WxOpenConfigStorage;
import me.chanjar.weixin.open.bean.WxOpenAuthorizerAccessToken;
import me.chanjar.weixin.open.bean.WxOpenComponentAccessToken;
Expand Down Expand Up @@ -46,9 +46,6 @@ public class WxOpenInMemoryConfigStorage implements WxOpenConfigStorage {
private Map<String, Token> cardApiTickets = new ConcurrentHashMap<>();
private Map<String, Lock> locks = new ConcurrentHashMap<>();

private Lock componentAccessTokenLock = getLockByKey("componentAccessTokenLock");


@Override
public boolean isComponentAccessTokenExpired() {
return System.currentTimeMillis() > componentExpiresTime;
Expand All @@ -64,11 +61,25 @@ public void updateComponentAccessToken(WxOpenComponentAccessToken componentAcces
updateComponentAccessToken(componentAccessToken.getComponentAccessToken(), componentAccessToken.getExpiresIn());
}

private Lock accessTokenLockInstance;

@Override
public Lock getComponentAccessTokenLock() {
if (this.accessTokenLockInstance == null) {
synchronized (this) {
if (this.accessTokenLockInstance == null) {
this.accessTokenLockInstance = getLockByKey("componentAccessTokenLock");
}
}
}
return this.accessTokenLockInstance;
}

@Override
public Lock getLockByKey(String key){
public Lock getLockByKey(String key) {
Lock lock = locks.get(key);
if (lock == null) {
synchronized (WxOpenInMemoryConfigStorage.class){
synchronized (this) {
lock = locks.get(key);
if (lock == null) {
lock = new ReentrantLock();
Expand Down

0 comments on commit 1e29d39

Please sign in to comment.