Stateless Bean -- class variables.


EJB design: Stateless Bean -- class variables.

  1. Stateless Bean -- class variables. (2 messages)

    Can you have a stateless session bean that actually has class variables? What would be the advantages and disadvantages of having them.

    I am hoping that i will get some good solution for this.
  2. Yes, Stateless Session EJB's can have non-final instance and static fields.

    By Stateless, EJB standards are refering to conversational state - state maintained between the EJB and a particular client. As long as the state held in the fields can be useful across client who are concurrently using the server (alternately using the EJB instance) then all is fine.

    For example, a Stateless Session EJB might cache database connections, references to other EJB's, etc. in its instance fields. Just make sure that it doesn't matter which client uses the EJB instance next.

  3. What if the container manages a pool of these stateless session beans!
    I mean how will it synchronize the reads and writes to the class variables then !!!
    Plus in a clustered environment i think having non-final static vars can cause problems.