You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dan Bunea <da...@linksystems.ro> on 2002/10/28 09:14:21 UTC

Huge action instance synchronization problem

 
My problem: I have a search action. When 2 (or more) users submit the
search form simultaniously, because the seach usually takes about 1-2
seconds, the same action instance is rethrieved to complete the search
and sessions are combined like this: the action makes the search for the
first session but does not finish until the second search is performed
and because the resultset is divided into pages and this divisation is
stored into session, both pages with results are put in the second
session, and the second user shall be dispalyed the correct results but
the first shall have null pointer exception because in his session there
is no object representing the divisation of the resultset on pages. 
 
The problem in my opinion is because the same action instance performs
the same task for the 2 users and so the sessions are combined, which is
a huge problem, because like this every method of an action (dispatch
action) that takes a while to complete shall have the same problem.
 
Please advise me how to solve this problem. 
Thank you , 
Dan Bunea
 
PS Dear Craig , I am sorry to bother you but this problem is very
urgent, as the project is in final stages and this is a potentially huge
problem.
 I have read that each action is instantiated only once in the
RequestProcessor and for each request the action is rethrieved and its
methods executed, but I have also read that this is not synchronized.
 

RE: Huge action instance synchronization problem

Posted by Dan Bunea <da...@linksystems.ro>.
I know it shouldn't have this problem. It is not the same session, nor
the same user that performs the search. Of course each user has the same
session, but let me explain some more of what I have seen happening.

The first user (say with session id #s1) obtains the action instance (
say instance #1) from the ActionServlet (RequestProcessr). The action
execute(..) starts executing, and makes the query into the database. At
this time the second request comes to the ActionServlet (say with
session id #s2), of course it has another session created for it,
obtains the same action instance as the the first user (#1), and because
the query in the database is not finished, the second user sets its
session into the action (#s2), so when the first query is finished I
call request.getSession()  it returns the second users session (#s2) for
both users, for the first that made the call and also for the second.
Now I have tried to make the execute () method synchronized but it did
not have any effect.

-----Original Message-----
From: Andrew Hill [mailto:andrew.david.hill@gridnode.com] 
Sent: Monday, October 28, 2002 10:33 AM
To: Struts Users Mailing List
Subject: RE: Huge action instance synchronization problem

The action instance itself doesnt have any member variables does it?
If you store stuff in the HTTPSession each user will have their own
session
context - it shouldnt (be possible to) get mixed up like that (unless
both
requests are actually by the same user (in the same session) - in which
case
you may have troubles like those you describe).

-----Original Message-----
From: Dan Bunea [mailto:danbunea@linksystems.ro]
Sent: Monday, October 28, 2002 16:14
To: struts-user@jakarta.apache.org
Cc: 'Craig R. McClanahan'
Subject: Huge action instance synchronization problem



My problem: I have a search action. When 2 (or more) users submit the
search form simultaniously, because the seach usually takes about 1-2
seconds, the same action instance is rethrieved to complete the search
and sessions are combined like this: the action makes the search for the
first session but does not finish until the second search is performed
and because the resultset is divided into pages and this divisation is
stored into session, both pages with results are put in the second
session, and the second user shall be dispalyed the correct results but
the first shall have null pointer exception because in his session there
is no object representing the divisation of the resultset on pages.

The problem in my opinion is because the same action instance performs
the same task for the 2 users and so the sessions are combined, which is
a huge problem, because like this every method of an action (dispatch
action) that takes a while to complete shall have the same problem.

Please advise me how to solve this problem.
Thank you ,
Dan Bunea

PS Dear Craig , I am sorry to bother you but this problem is very
urgent, as the project is in final stages and this is a potentially huge
problem.
 I have read that each action is instantiated only once in the
RequestProcessor and for each request the action is rethrieved and its
methods executed, but I have also read that this is not synchronized.



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Huge action instance synchronization problem

Posted by Andrew Hill <an...@gridnode.com>.
The action instance itself doesnt have any member variables does it?
If you store stuff in the HTTPSession each user will have their own session
context - it shouldnt (be possible to) get mixed up like that (unless both
requests are actually by the same user (in the same session) - in which case
you may have troubles like those you describe).

-----Original Message-----
From: Dan Bunea [mailto:danbunea@linksystems.ro]
Sent: Monday, October 28, 2002 16:14
To: struts-user@jakarta.apache.org
Cc: 'Craig R. McClanahan'
Subject: Huge action instance synchronization problem



My problem: I have a search action. When 2 (or more) users submit the
search form simultaniously, because the seach usually takes about 1-2
seconds, the same action instance is rethrieved to complete the search
and sessions are combined like this: the action makes the search for the
first session but does not finish until the second search is performed
and because the resultset is divided into pages and this divisation is
stored into session, both pages with results are put in the second
session, and the second user shall be dispalyed the correct results but
the first shall have null pointer exception because in his session there
is no object representing the divisation of the resultset on pages.

The problem in my opinion is because the same action instance performs
the same task for the 2 users and so the sessions are combined, which is
a huge problem, because like this every method of an action (dispatch
action) that takes a while to complete shall have the same problem.

Please advise me how to solve this problem.
Thank you ,
Dan Bunea

PS Dear Craig , I am sorry to bother you but this problem is very
urgent, as the project is in final stages and this is a potentially huge
problem.
 I have read that each action is instantiated only once in the
RequestProcessor and for each request the action is rethrieved and its
methods executed, but I have also read that this is not synchronized.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Huge action instance synchronization problem

Posted by "Craig R. McClanahan" <cr...@apache.org>.
As others have pointed out, 99.9% of this kind of a problem comes from
using class-level instance variables (also called member variables) to
store information that is specific to a particular request.  This fails
because there is only one instance of the Action, so the instance
variables are shared across multiple requests.

Actions must be designed in a thread-safe manner.  In particular, you
should never use instance variables in an Action class, unless you
SPECIFICALLY intend to share that variable across multiple users.

Variables local to the perform() or execute() method are not shared, so
that is where you should store things specific to a particular request.

Craig

On Mon, 28 Oct 2002, Dan Bunea wrote:

> Date: Mon, 28 Oct 2002 10:14:21 +0200
> From: Dan Bunea <da...@linksystems.ro>
> Reply-To: Struts Users Mailing List <st...@jakarta.apache.org>
> To: struts-user@jakarta.apache.org
> Cc: 'Craig R. McClanahan' <Cr...@eng.sun.com>
> Subject: Huge action instance synchronization problem
>
>
> My problem: I have a search action. When 2 (or more) users submit the
> search form simultaniously, because the seach usually takes about 1-2
> seconds, the same action instance is rethrieved to complete the search
> and sessions are combined like this: the action makes the search for the
> first session but does not finish until the second search is performed
> and because the resultset is divided into pages and this divisation is
> stored into session, both pages with results are put in the second
> session, and the second user shall be dispalyed the correct results but
> the first shall have null pointer exception because in his session there
> is no object representing the divisation of the resultset on pages.
>
> The problem in my opinion is because the same action instance performs
> the same task for the 2 users and so the sessions are combined, which is
> a huge problem, because like this every method of an action (dispatch
> action) that takes a while to complete shall have the same problem.
>
> Please advise me how to solve this problem.
> Thank you ,
> Dan Bunea
>
> PS Dear Craig , I am sorry to bother you but this problem is very
> urgent, as the project is in final stages and this is a potentially huge
> problem.
>  I have read that each action is instantiated only once in the
> RequestProcessor and for each request the action is rethrieved and its
> methods executed, but I have also read that this is not synchronized.
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>