【发布时间】:2011-01-21 04:18:27
【问题描述】:
我尝试将用户会话保存在每个集群的哈希图中。当我需要使其无效时,我将采用指定的会话 ID。并在会话以正常方式使会话无效的地方使其无效。
public class SessionListener implements HttpSessionListener {
public HashMap<String, HttpSession> sessionHolder = new HashMap<String, HttpSession>();
@Override
public void sessionCreated(HttpSessionEvent se) {
sessionHolder.put(se.getSession().getId(), se.getSession());
}
public void invalidate(String sessionId){
if(this.sessionHolder.get(sessionId)!= null){
System.out.println("Invalidate session ID : " + sessionId);
HttpSession session = sessionHolder.get(sessionId);
session.invalidate();
} else {
System.out.println("Session is not created in this cluster ID : " + sessionId);
}
}
@Override
public void sessionDestroyed(HttpSessionEvent se) {
System.out.println("Session " + se.getSession().getId() + " has been destoryed");
sessionHolder.remove(se.getSession().getId());
}
}
会话将在无效发生的地方消失。但在其他集群会话上仍然可用。
为什么其他集群上的会话仍然存在。以及如何使其他集群上的会话失效。
谢谢。
【问题讨论】:
-
您说的是多个集群。你有集群间复制吗? (download.oracle.com/docs/cd/E11035_01/wls100/cluster/…)
-
什么是集群间复制?如果您的意思是会话将在集群中复制,是的。
-
您正在写“其他集群上的会话”。有多少个集群?
-
我配置了大约 2 个集群在一台机器上运行(实际上是我的笔记本电脑)。我还没有尝试在其他机器上。如果我像上面那样,我不明白为什么 weblogic 不能使其他集群上的所有会话无效。但是当我以普通方式使会话无效时,它的成功(从http请求中获取会话)。有什么线索吗?
-
我猜您将集群与服务器混淆了。请检查您的域配置 (download.oracle.com/docs/cd/E11035_01/wls100/cluster/…) 并检查会话复制配置是否正确 (download.oracle.com/docs/cd/E11035_01/wls100/cluster/…)。
标签: session jakarta-ee weblogic invalidation