🎨 优化部分代码

This commit is contained in:
Binary Wang
2020-05-21 21:10:43 +08:00
parent 50e50c13c4
commit 5c7b6d2af4
2 changed files with 25 additions and 30 deletions

View File

@@ -1,21 +1,19 @@
package me.chanjar.weixin.common.session;
import me.chanjar.weixin.common.util.res.StringManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import me.chanjar.weixin.common.util.res.StringManager;
/**
* 基于内存的session manager.
*
* @author Daniel Qian
*/
public class StandardSessionManager implements WxSessionManager, InternalSessionManager {
protected static final StringManager SM = StringManager.getManager(Constants.PACKAGE);
/**
* The descriptive name of this Manager implementation (for logging).
@@ -51,7 +49,9 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
*/
protected int maxInactiveInterval = 30 * 60;
// Number of sessions created by this manager
/**
* Number of sessions created by this manager
*/
protected long sessionCounter = 0;
protected volatile int maxActive = 0;
@@ -154,12 +154,10 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
session.setValid(true);
session.setCreationTime(System.currentTimeMillis());
session.setMaxInactiveInterval(this.maxInactiveInterval);
String id = sessionId;
session.setId(id);
session.setId(sessionId);
this.sessionCounter++;
return (session);
return session;
}
@@ -181,10 +179,8 @@ public class StandardSessionManager implements WxSessionManager, InternalSession
return new StandardSession(this);
}
@Override
public void add(InternalSession session) {
// 当第一次有session创建的时候开启session清理线程
if (!this.backgroundProcessStarted.getAndSet(true)) {
Thread t = new Thread(new Runnable() {