Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting the same instance of an SFSB  RSS feed

 
Shekar Atmakur
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This may be a basic question but all ask it all the same.

I need to create a SFSB and keep using only one instance of that SFSB( i need to reuse information stored in that bean).
These is the only option i know of:

Create the Bean, get a "Handle" to the bean and store it somewhere and keep using it to get the same instance.

The problem i have in this case is, i cannot store this "Handle" in session
since the session is associated to a client, and i want to use the same instance of the SFSB across multiple sessions and share information.
Also i cannot use a singleton class since it will not work in a clustered environment.

Now, is there some mechanism i can store the "Handle" to the SFSB in the application server's context that can be used across multiple sessions or Is there some way i can retrieve the reference to the SFSB.

Please let me know if my question was too generic to understand. I'll try to give a more specific scenario.

Any help is appreciated.

thanks,
shekar
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Handle cannot help you. It is a Serializable object which is able to give you the stub to the EJBObject. You can use this stub from another machine to invoke the stateless session bean's method. But once that method has completed successfully, the container will return the bean instance to the pool. So, you will not have access to any of the bean's variables.

You may be able to do something with a stateful session bean, but note that the container can kill the bean after the timeout period even if it was passivated.
 
Shekar Atmakur
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering what i could do with a stateful session bean.
thanks,
shekar
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shekar ,


The problem i have in this case is, i cannot store this "Handle" in session
since the session is associated to a client, and i want to use the same instance of the SFSB across multiple sessions and share information.

This might be a problem though. Having multiple clients talking to the same SFSB instance is definitely a very poor design decision. The reason is very simple: it will raise multithreading issues and you have to code the bean access in a thread safe manner. By doing this you�ll defeat the whole purpose of using ejbs. This is why the container creates a pool of instances and has each client talking to a unique instance. You might think that it could work if the bean caches only read-only data. But you must realize that the container can passivate and finally remove the bean if an idle time is passed and your handler becomes useless. Bottom line is that having the handler stored to some other persistence storage like a network file or database is mostly not going to work, simply because SFSB were not designed to be used as cluster caching strategies. You might also like trying other strategies: Weblogic for example uses read-only ejbs that could make great caching solutions. JBoss has its own caching strategy as well, allowing an entire graph of pojos to be cached across the cluster. You might consider employing vendor specific technologies and forget about the J2EE compatible crap.
Regards.
 
Shekar Atmakur
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Valentin,
Thank you very much for the explaination. It has made my thoughts more clear now. I had actually completed my coding of placing the Handle in a persistant storage and had overlooked the issue of passivation. I will now do a little more research into read-only entity ejb's. I think that is the best solution in my case, since it takes care of failover(which is my actual issue) and fault-tolerance.

thanks,
shekar
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're very welcome Shekar. I'm glad I could help
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!