Invalidate Session at all Cluster Weblogic

半世苍凉 提交于 2020-01-06 02:56:05

问题


i try to save user session in a hashmap on every cluster. and when i need to invalidate it, i will take specified session id. and invalidate it where the session created with normal way to invalidate session.

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());
 }
}

session will perish where invalidate occur. but on other cluster session is still avaliable.

why the session on other cluster is still. and how to also invalidate session on other cluster.

thanks.


回答1:


(it would be good to confirm whether we're talking about servers or clusters - the config.xml for your domain would be a help)

The session object is only managed by WebLogic Server inside the web container - if you create a copy of the session object in a HashMap manually either in another server or another cluster entirely, WebLogic Server won't automatically invalidate the copy of that session object, because it's outside of the web container.

WebLogic Server will automatically, and quite transparently create a replicated copy of HttpSession objects provided that your <session-descriptor> element in your weblogic.xml deployment descriptor has correct settings (replicated_if_clustered for persistent-store-type is recommended)

Doc available here: http://download.oracle.com/docs/cd/E13222_01/wls/docs103/webapp/weblogic_xml.html#wp1071982

It would be good to understand what you're trying to achieve here - cross-cluster replication shouldn't be necessary unless you're talking about a monster application or spanning a wide network segment, although it is supported with WebLogic Server.



来源:https://stackoverflow.com/questions/4755323/invalidate-session-at-all-cluster-weblogic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!