2 Replies Latest reply on Nov 21, 2006 8:22 PM by khairul anwar

    username and session caching

    khairul anwar Newbie

      Hi, for your information, I've done a very simple/basic caching using jbosscache about 5 months ago and left it since then. In what have been done, I'm accessing a jbosscache(Mbean) and put a user session id in it. The article that I'm following is here


      What happen is the data is not shared and each user have their own unique session id, which is exactly what I want it to be. I use JbossAS 4.0.4RC2 or 4.0.2 that time and maybe JbossCache 1.3(can't remember well, including the setting).

      However when i tried it now with JbossAS 4.0.5 and Jboss 1.4, It doesn't work anymore. Instead the data that being put into cache will be overrided by a data from a second user. So now a first user will get a second user's session id, not his own.

      The code use to put and get the data from jboss cache is as follow

      private Option option = new Option();
      private Fqn fqn =new Fqn("/user/session");
      private Map<String, String> map = new HashMap<String, String>();
      private TreeCacheMBean cache;
      private TreeCacheMBean getTreeCacheMBean() {
       if (cache == null) {
       try {
       log.info("TreeCacheMBean is null");
       cache = (TreeCacheMBean) MBeanProxyExt.create(
       "jboss.cache:service=TomcatClusteringCache", server);
       } catch (MalformedObjectNameException e) {
       // TODO Auto-generated catch block
       return cache;
      public void insertSession(String sessionID, String userId) throws Exception {
       map.put("userId", userId);
       cache = getTreeCacheMBean();
       cache.put(fqn,"sessionId", sessionId, option);
       log.info("End input into cache");
      public String getSession() throws Exception {
       String session = "";
       cache = getTreeCacheMBean();
       session = (String) cache.get(fqn,"sessionId",option);
       return session;

      I try to search in forum and found this


      which is very-very similar with what I want to do. The question that puzzling me is can jboss cache automatically know who is whom in concurrent access? I means if it is able make a differentiate each user access without the data being overrided by newest insertion. I want to confirm whether my first try is really working or just my mistake in doing testing. If it is able to differentiate a user, then can you point me to configuration that need to be done? I read about locking and concurrency access but not found what i need. Sorry, a newbie here.

      Thanks so much,