Static Variable in EJB(Session Bean)


EJB programming & troubleshooting: Static Variable in EJB(Session Bean)

  1. Static Variable in EJB(Session Bean) (6 messages)

    Is it advaisable to use Static Variables in a Sesssion Bean.?

  2. Hi Rajesh,
    This is not a good idea to use,
    My idea is when you put business logic in Sessionbeans
    why do you want to put some static Varibles in.
    How do you like to take care of multiple instancess runing and server quickly.
    with regs
    Any comments welcome
  3. Hi,

      why not to use it as an easy way of caching some objects?

      For example, something wich it has had to be read from a file (to read only once).It it´s the same object for all the session EJBs... Or is it better to make an standalone class?


         Jose R.
  4. AFAIK, there shouldn't be a problem as long as you don't assume different session bean instances will see the same static variable (they may run in different VMs or under different class-loaders).
    Of course, you have to pay attention to multi-threading issues just like in any other class.

  5. Static Variable in EJB(Session Bean)[ Go to top ]

    I have a Session Bean.(SB) and a normal java class "Slot".

    The Session Bean(SB) Should create an instance of Class Slot and deliver it to the client.
    The Session Bean(SB) Should also maintain a list of Slots created.(e.g. In a Vector).

    how can i maintain a list of Slot instances in a Session Bean?. (Without a Static varible?).
    I know the problem of Multiple JVM incompatability in case of Static Variable.

    Viswa/Jose/Gal can u give a nice suggestion for this case.

    Using Singleton Class in this case is advisable?

    If possible mail ur comments to "vrkraj at rediffmail dot com".


    Client :
    Slot myslot = remote_of_SB.authorize(userid);

    where authorize is a Business Method.

    Waiting near Inbox.


  6.   You will have problems with Singleton Class if there is a cluster.
      your problem may require to save your data, slots, in database or some common repository, maybe JNDI? So your Session Beans could access to the slots repository.

      If yo have the solution, please let me know it....


         Jose R.

  7. Hello.
    You should think about appservers mainly as STATELESS.They are logic processors.The STATE is the DATABASE.