mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-09-08 22:20:43 +00:00
perf[session]: use local atomic variables
This commit is contained in:
@@ -14,10 +14,10 @@ package com.zfoo.net.session;
|
||||
|
||||
import com.zfoo.net.util.SessionUtils;
|
||||
import com.zfoo.protocol.collection.concurrent.ConcurrentHashMapLongObject;
|
||||
import com.zfoo.util.security.IdUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
@@ -28,6 +28,8 @@ public class SessionManager implements ISessionManager {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(SessionManager.class);
|
||||
|
||||
private static final AtomicInteger CLIENT_ATOMIC = new AtomicInteger(0);
|
||||
|
||||
/**
|
||||
* 作为服务器,被别的客户端连接的Session
|
||||
* 如:自己作为网关,那肯定有一大堆客户端连接,他们连接上来后,就会保存下来这些信息。
|
||||
@@ -42,7 +44,7 @@ public class SessionManager implements ISessionManager {
|
||||
*/
|
||||
private final ConcurrentHashMapLongObject<Session> clientSessionMap = new ConcurrentHashMapLongObject<>(8);
|
||||
|
||||
private volatile int clientSessionChangeId = IdUtils.getLocalIntId();
|
||||
private volatile int clientSessionChangeId = CLIENT_ATOMIC.incrementAndGet();
|
||||
|
||||
|
||||
@Override
|
||||
@@ -87,7 +89,7 @@ public class SessionManager implements ISessionManager {
|
||||
return;
|
||||
}
|
||||
clientSessionMap.put(session.getSid(), session);
|
||||
clientSessionChangeId = IdUtils.getLocalIntId();
|
||||
clientSessionChangeId = CLIENT_ATOMIC.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,7 +101,7 @@ public class SessionManager implements ISessionManager {
|
||||
try (session) {
|
||||
clientSessionMap.remove(session.getSid());
|
||||
}
|
||||
clientSessionChangeId = IdUtils.getLocalIntId();
|
||||
clientSessionChangeId = CLIENT_ATOMIC.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user