EJB design: Using static variables in stateless session beans(SSB)

  1. Hi, I have confusion over the behaviour of static variables in SSB.Actually i am facing a problem,in SSB a static integer variable(STIV) has been declared which is used to iterate String array(which conatains Names of the JMS queues to which messages are send.This caching of JMS queue names is done in other helper class ). Ocasionnally what is happening while iterating the Static String array(declared in helper class) using the static integer variable(STIV) declared in SSB i am getting arrayOutOfIndex array. This happens in one out 5000 transactions processed by the SSB The helper class is not synchronized The application used is Weblogic Please help me to clarify my dbouts abt the Static variable usage in SSB
  2. hi, This is what I think... App server creates multiple EJB objects and stores them in a pool. When needed EJB is retrieved from the pool.. used.. and returned back to the pool. Similar to JDBC connection pool. Now it is totally upto the server implementation which decides when to flush the complete pool and re-create fresh objects. When flushing happens.. then all the objects are destroyed and your static variable gets re-initialized. Keeping a Static variable in a EJB is not at all a good idea.
  3. ...
    Keeping a Static variable in a EJB is not at all a good idea.
    Agree: static objects are not permitted by the J2EE specification because you never know how many class loaders there are in your Web/EJB container. Therefore, the static object will be unique in the class loader only. If there are multiple class loaders, your static object will exist more than once (1 instance per class loader).