You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bryan Field-Elliot <br...@netmeme.org> on 2001/04/05 17:08:59 UTC

Frames, concurrency, and EJB Stateful Session beans - a problem.

I'm having a design problem with my system, which is not really Struts 
specific, but since there are a lot of EJB users here, I thought I'd 
throw it on this list for comments --

My business logic is all implemented in a Stateful EJB Session bean. All 
Struts users get one instance of the session bean, whose reference is 
stored in the Servlet's Session scope.

All of my Struts actions are simple; they take data from the user 
(usually in ActionForms), pass them to some method in the EJB Session 
bean, and store the results in beans for the JSP page to render.

However, my design calls for a few places where there is a frameset, and 
in another place, where two browser windows open up showing two 
different views. The problem here, is that EJB requires that a Stateful 
Session bean have only one thread of execution within it (e.g. no 
concurrency). So, when two different Struts actions (or custom tags) try 
to invoke a method on the same EJB Session bean reference at the same 
time, one of them will fail with an exception thrown by the EJB 
container (in my case, jBoss).

Can anyone recommend an easy, general-purpose solution to this problem? 
(Please don't say, "switch to stateless session beans"). I suppose I 
need to syncronize access to the EJB bean from the client (and, in this 
case, the client is Struts), but I'm not sure how to do this quickly and 
elegantly.

Comments would be appreciated,

Bryan



Re: Frames, concurrency, and EJB Stateful Session beans - a problem.

Posted by Bryan Field-Elliot <br...@netmeme.org>.
Now that I think about it, perhaps a solution to this would be a great 
general-purpose configuration feature for Struts. On a 
per-web-application level (e.g. in struts-config.xml), there might be an 
option such as:

syncronize_requests = xxxxx

where xxxxx might be:

none - the default -- the current Struts behavior
session - syncronize requests on a per user (per-session) basis (but 
allow concurrent access from different users)
application - syncronize all requests, globally

This would be to support whacko frameworks like EJB, whereby you can't 
have concurrent access to Stateful Session Beans. (in that scenario I 
would use "session" rather than "application" syncronization).

Note also (and this is very important) -- that if this were to be a 
general-purpose Struts mechanism, I would need to be able to tie into it 
from my custom tag library, as well as my Action classes, since tags 
might also access an EJB bean.

Regards,

Bryan



Re: Frames, concurrency, and EJB Stateful Session beans - a problem.

Posted by Bryan Field-Elliot <br...@netmeme.org>.
Thanks,

That proposal would probably work, but it might be a little 
over-complicated (although I am starting to suspect that every solution 
is going to be yucky). I think I couldn't do your idea with just a 
simple bean with a simple syncronized getter method; instead, the 
wrapper bean would have to have all of the same method signatures as the 
session bean, and pass through all the calls (doing syncronization first).

What I'm leaning towards right now, is finding some kind of "per-user" 
syncronization, which I can "lock" at the start, and "unlock" at the 
end, of every one of my Action.perform() methods. I can probably do this 
with a simple class, with two static methods -- "lock" and "unlock" -- 
and it will take as a parameter the current user's "session" object 
(Servlet session, that is), so that the locks are per-user, rather than 
global.

Comments before I dive in the deep end?

Thanks,

Bryan

Abraham Kang wrote:

> Hi Bryan,
> 
> 	Can you put the stateful session bean within a JavaBean with synchronized
> methods so that all access to the stateful session bean is through the
> JavaBean?
> 
> --Abraham
> 
>> -----Original Message-----
>> From: Bryan Field-Elliot [mailto:bryan_lists@netmeme.org]
>> Sent: Thursday, April 05, 2001 8:09 AM
>> To: struts-user@jakarta.apache.org
>> Subject: Frames, concurrency, and EJB Stateful Session beans - a
>> problem.
>> 
>> 
>> I'm having a design problem with my system, which is not really Struts
>> specific, but since there are a lot of EJB users here, I thought I'd
>> throw it on this list for comments --
>> 
>> My business logic is all implemented in a Stateful EJB Session bean. All
>> Struts users get one instance of the session bean, whose reference is
>> stored in the Servlet's Session scope.
>> 
>> All of my Struts actions are simple; they take data from the user
>> (usually in ActionForms), pass them to some method in the EJB Session
>> bean, and store the results in beans for the JSP page to render.
>> 
>> However, my design calls for a few places where there is a frameset, and
>> in another place, where two browser windows open up showing two
>> different views. The problem here, is that EJB requires that a Stateful
>> Session bean have only one thread of execution within it (e.g. no
>> concurrency). So, when two different Struts actions (or custom tags) try
>> to invoke a method on the same EJB Session bean reference at the same
>> time, one of them will fail with an exception thrown by the EJB
>> container (in my case, jBoss).
>> 
>> Can anyone recommend an easy, general-purpose solution to this problem?
>> (Please don't say, "switch to stateless session beans"). I suppose I
>> need to syncronize access to the EJB bean from the client (and, in this
>> case, the client is Struts), but I'm not sure how to do this quickly and
>> elegantly.
>> 
>> Comments would be appreciated,
>> 
>> Bryan
>> 
>> 
>> 


RE: Frames, concurrency, and EJB Stateful Session beans - a problem.

Posted by Abraham Kang <ab...@infogain.com>.
Hi Bryan,

	Can you put the stateful session bean within a JavaBean with synchronized
methods so that all access to the stateful session bean is through the
JavaBean?

--Abraham

> -----Original Message-----
> From: Bryan Field-Elliot [mailto:bryan_lists@netmeme.org]
> Sent: Thursday, April 05, 2001 8:09 AM
> To: struts-user@jakarta.apache.org
> Subject: Frames, concurrency, and EJB Stateful Session beans - a
> problem.
>
>
> I'm having a design problem with my system, which is not really Struts
> specific, but since there are a lot of EJB users here, I thought I'd
> throw it on this list for comments --
>
> My business logic is all implemented in a Stateful EJB Session bean. All
> Struts users get one instance of the session bean, whose reference is
> stored in the Servlet's Session scope.
>
> All of my Struts actions are simple; they take data from the user
> (usually in ActionForms), pass them to some method in the EJB Session
> bean, and store the results in beans for the JSP page to render.
>
> However, my design calls for a few places where there is a frameset, and
> in another place, where two browser windows open up showing two
> different views. The problem here, is that EJB requires that a Stateful
> Session bean have only one thread of execution within it (e.g. no
> concurrency). So, when two different Struts actions (or custom tags) try
> to invoke a method on the same EJB Session bean reference at the same
> time, one of them will fail with an exception thrown by the EJB
> container (in my case, jBoss).
>
> Can anyone recommend an easy, general-purpose solution to this problem?
> (Please don't say, "switch to stateless session beans"). I suppose I
> need to syncronize access to the EJB bean from the client (and, in this
> case, the client is Struts), but I'm not sure how to do this quickly and
> elegantly.
>
> Comments would be appreciated,
>
> Bryan
>
>
>