public class ResourceLog implements Runnable { public static Map<String, HttpSession> sessionMap = new HashMap<String, HttpSession>(); .......... }
系統啓動執行以下,開啓線程服務器
ResourceLog resourceLog = new ResourceLog(); Thread thr = new Thread(resourceLog, "資源log記錄"); thr.start();
//登陸 HttpSession session = request.getSession(); String sessionId = session.getId(); ResourceLog.sessionMap.put(sessionId, session);
//退出 HttpSession session = request.getSession(); String sessionId = session.getId(); ResourceLog.sessionMap.remove(sessionId);
ResourceLog.sessionMap.size();