• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing Stateful Session Beans

 
Amit Chawla
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Our Web Application maintains the conversational state using a stateful session bean. This bean needs to be accessed by multiple JSP pages in a frame.
Now, as per the EJB specification, these pages can't execute methods on the SFSB concurrently. Therefore, I want to synchronize the access to the SFSB(The Remote object is being maintained in the HttpSession).
How Can I do this? What is the best way to do this?
Regards,
Amit
Sr. Architect
Fusion Technology Group

[This message has been edited by Amit Chawla (edited March 26, 2001).]
 
Madhu Juneja
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need not do the synchronization yourself. It is done by the container. In fact the ejb specs say that the bean developer should not handle synchronization issues.
Concurrency is one of the primary functions of the container. And the way it does is : it creates an instance or rather uses a new bean instance from the pool for every request, passivating and activating the bean instances as and when required in the process.
 
Amit Chawla
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx for the reply Madhu.
I understand that the container should be responsible for the tasks, such as, object management, transaction management, synchronization etc.
And to tell you honestly, I am not interested in writing any plumbing code to do things that I am not supposed to. But, the poblem is:
When two methods are called concurrently on the stateful session bean the container throws the following exception:
LockTimedOutException: Lock for primaryKey:954117372526_4 could not be acquired without waiting.
I have figured a 'work-around' to get over this problem. That is, I catch the LockTimedOutException exception in all the JSP pages in the frame. In the catch block, I make the current thread sleep for a while and re-execute the statement [re-access the conversational state]. Here is the code:
<%page language = "java">
[snip]
<HTML>
[snip]
<%
RORACApplicationRemote roracApplication; // Remote object declaration
roracApplication = (RORACApplicationRemote) session.getAttribute("RORACApplication"); //get the remote-ref from the session
try {
userDetails = roracApplication.getUserDetails(); //Execute the method on the remote object
}
catch (weblogic.ejb.extensions.LockTimedOutException ex) {
Thread.sleep(100); // Hang on for a while!
userDetails = roracApplication.getUserDetails();//Try again, but, if this fails then I have say Sorry with a capital S
}
%>
[snip]
</html>

The above fix works fine but does not guarantee to pass all tests... Do you have any ideas on this?
 
Madhu Juneja
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be you could give a delay in a loop until the method is executed successfully. And also instead of delay in the catch block place the delay in the try block.
Also refer :
http://www.javaranch.com/ubb/Forum7/HTML/002672.html http://www.javaranch.com/ubb/Forum7/HTML/002665.html http://www.javaranch.com/ubb/Forum7/HTML/002716.html
Although the above links highlight delay in redirecting to another jsp page and your problem refers to execution of methods of the bean class. May be they will provide some insight.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!