2 Replies Latest reply on Jul 25, 2011 4:32 AM by sjunejo

    Separate Static Instances Used in Web Application

    sjunejo

      Hi,

       

      I have a class in my web applications which is responsible to lookup resources i.e Cx Factories and store objects in MAP for performace. Now if I deploy two instance of this application on jBoss 5+ both end up using the same MAP. How can I make both application to use it own separet heap so both should use their own MAPS generated. If I do not generate MAP, both works fine. Is there anything I can change in jboss-classloading.xml?

       

      You help and comments will be appreciated.

       

      Thanks,

       

      --

       

      SJunejo

        • 1. Re: Separate Static Instances Used in Web Application
          sjunejo

          Some more information regarding the above problem. In my web application, I have class called AgentConnector.java which has following code;

          ServiceLocator asl = null;

          asl = ServiceLocator.getInstance();

          XConnectionFactory cxf = asl.lookupXConnectionFactory();

           

          My ServiceLocator class is responsible for lookups and code is as follows;

           

               public final static String XCONNECTION_FACTORY_JNDI_NAME = "java:comp/env/jca/xConnectionFactory";

           

               private static ServiceLocator _instance = null;

           

               private InitialContext _context = null;

           

              private Map<String, XConnectionFactory> _cacheXConnectionFactory = null;

           

              public ServiceLocator() {

                  try {

                      _context = new InitialContext();

                  } catch (NamingException e) {

                      throw new RuntimeException("Configuration error - cannot create initial context");

                  }

                  _cacheXConnectionFactory = Collections.synchronizedMap(new HashMap<String, XConnectionFactory>());

              }

           

           

              public static synchronized ServiceLocator getInstance() {

                  if (_instance == null) {

                      _instance = new ServiceLocator();

                  }

                  return _instance;

              }

           

              public XConnectionFactory lookupXConnectionFactory() {

                  XConnectionFactory cxFactory = null;

                  try {

                      if (_cacheXConnectionFactory.containsKey(XCONNECTION_FACTORY_JNDI_NAME)) {

                          cxFactory = _cacheXConnectionFactory.get(XCONNECTION_FACTORY_JNDI_NAME);

                      } else {

                          Object factoryObj = _context.lookup(XCONNECTION_FACTORY_JNDI_NAME);

                          cxFactory = (XConnectionFactory) factoryObj;

                          _cacheXConnectionFactory.put(XCONNECTION_FACTORY_JNDI_NAME, cxFactory);

                      }

                  } catch (NamingException e) {

                      // LOGGER.fatal("Configuration error " + e.getMessage(), e);

                      throw new RuntimeException("Configuration error [" + XCONNECTION_FACTORY_JNDI_NAME + "] " + e.getMessage());

                  }

           

                  return cxFactory;

              }

           

          Now, If I deploy two instances of this application in single jboss 5.1+ instance, both will end up using single instnace of 'ServiceLocator' object because it is 'static'. Now is there anyway I can restrict the access of this 'ServiceLocator' i.e. Second instance should create its own ServiceLocator instance and use it rather than the one created by first instance. I want to acheive this without changing my code but with the help of configurations, class-loading etc etc?

           

          Thanks,

           

          --

           

          SJunejo

          • 2. Re: Separate Static Instances Used in Web Application
            sjunejo

            Please refer to the link for the possible solution and information.

             

            http://community.jboss.org/message/617331#617331