I have a particular requirement within my Portal Project where I have to use Stateful Session EJB. I have two portlets on the same page accessing the statefull session bean. When I am using parallel rendering , I get an exception because two threads are accessing the same stateful session bean. I understand that this is as per EJB Specification.
My question is how do I synchronize access to the stateful session bean. Clients objects interace with the SFSB through a business delegate. If I synchronize the access methods in Business Delegate, this will mean all threads belonging to all users will be affected(Hope I am correct). All I want to do is synchronize the threads belonging to the same user.
I was thinking about wrapping the EJB Handle with a custom class in order to achieve this. Because EJB Handle is for a particular instance of a SFSB, and the clients use the EJB Handle to get to the SFSB object once it is created, I was thinking about creating a custom object and storing the EJB Handle in that object. The class will have a single method
public synchronized EJBObject getEJBObject() which inturn will call the getEJBObject in the EJBHandle object. Clients will use this custom object instead of EJB Handle directly to get to SFSB.
Is there anything wrong with this approach? Am I missing something? Your comments and suggestions will be greatly appreciated.