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). What is the best way to do this?

Govind Seshadri

Answer by Michael Wax Re: Accessing EJBs in JSP pages

You could store the remote object in an object with synchronized access in the HttpSession or in a singleton object on your web server.

However, are you really sure that you want to go this route? Taking the frames out would solve your problem without the need for an expensive synchronization mechanism. (In the view of many web developers and usability engineers, taking the frames out would also enhance the appearance and usability of your site.)

Answer by Amit Chawla Re: Re: Accessing EJBs in JSP pages The need for frames in the application is mandatory, since there are many UI elements that need to be displayed in one go...
When you say, "You could store the remote object in an object with synchronized access in the HttpSession" What does this mean?
Here is my implementation:
<%@ page language='Java'%>
<%@ page import= [snip]%>
RORACApplicationRemote roracApplication;
UserDetails userDetails=null;
roracApplication = (RORACApplicationRemote) session.getAttribute ("RORACApplication");
userDetails = roracApplication.getUserDetails();
When I have this code in two JSP pages in a frame, and is executed concurrently, It results is the LockTimedOutException....
How do I synchronize the access to the remote object??

Answer by Michael Wax Re: Re: Re: Accessing EJBs in JSP pages

What I was thinking of was something like this to replace your code in the jsp:

SynchronizedAccessor accessor = session.getAttribute ("SynchronizedAccessor");
UserDetails userDetails = accessor.getUserDetails();

The big difference here is that you are not getting the remote object directly from the session anymore. The SynchronizedAccessor class would contain the remote object instance, and the getUserDetails method would be synchronized so that only one frame jsp could call a method on the remote object at any given time.


public class SynchronizedAccessor {
 private RORACApplicationRemote roracApplication;
  public synchronized UserDetails
  getUserDetails () {
    return roracApplication.getUserDetails();

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact