You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Kalra, Ashwani" <as...@capgemini.com> on 2005/04/08 13:10:02 UTC

concurrency problem

I am facing concurrency problem in following scenario.

All our action classes call same stateful session bean .  Each action class obtains the reference  from HTTPSession object and calls one and only one business method.
To prevent the concurrent access to this instance which occurs when user immediately presses two links quickly in succession I am using the following code block


execute(...)  //execute methods of Action class
{
....
....

//Obtain the session from  Request.User will always be in session here
session=request.getSession()
Synchronised(session)
{
    //call ejb's  business method.
}

}

However sometimes  more than one thread is able to pass through, And I get exception from Appserver. As 2 threads are not allowed for statefull Session bean.
Can there be problem in above code. Is it ok to synchronise on session object.





Thanks & Regds
 Ashwani

Ext: 1860







This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient,  you are not authorized to read, print, retain, copy, disseminate,  distribute, or use this message or any part thereof. If you receive this  message in error, please notify the sender immediately and delete all  copies of this message.

Re: concurrency problem

Posted by James Mitchell <jm...@apache.org>.
You'd be better off implementing token processing.

Struts includes token generation and helper methods to ensure only one valid 
request is handled at a time.  Look at the struts example application 
(mailreader) for an example.

For detailed info on why this pattern works, see:
http://www.amazon.com/exec/obidos/tg/detail/-/0201634988/ref=lpr_g_1/102-8250064-5792120?v=glance&s=books




--
James Mitchell
Software Engineer / Open Source Evangelist
Consulting / Mentoring / Freelance
EdgeTech, Inc.
678.910.8017
AIM:   jmitchtx
Yahoo: jmitchtx
MSN:   jmitchell@apache.org




----- Original Message ----- 
From: "Kalra, Ashwani" <as...@capgemini.com>
To: "Struts (E-mail)" <us...@struts.apache.org>
Sent: Friday, April 08, 2005 7:10 AM
Subject: concurrency problem



I am facing concurrency problem in following scenario.

All our action classes call same stateful session bean .  Each action class 
obtains the reference  from HTTPSession object and calls one and only one 
business method.
To prevent the concurrent access to this instance which occurs when user 
immediately presses two links quickly in succession I am using the following 
code block


execute(...)  //execute methods of Action class
{
....
....

//Obtain the session from  Request.User will always be in session here
session=request.getSession()
Synchronised(session)
{
    //call ejb's  business method.
}

}

However sometimes  more than one thread is able to pass through, And I get 
exception from Appserver. As 2 threads are not allowed for statefull Session 
bean.
Can there be problem in above code. Is it ok to synchronise on session 
object.





Thanks & Regds
 Ashwani

Ext: 1860







This message contains information that may be privileged or confidential and 
is the property of the Capgemini Group. It is intended only for the person 
to whom it is addressed. If you are not the intended recipient,  you are not 
authorized to read, print, retain, copy, disseminate,  distribute, or use 
this message or any part thereof. If you receive this  message in error, 
please notify the sender immediately and delete all  copies of this message.



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: concurrency problem

Posted by Je...@bcbstx.com.



Maybe I'm being dense here but:

If every session contains a reference to the bean, and every thread is
synchronizing on their own session;

It would seem that there would not be any concurrency control.

I would think that they all need to sync on the same object.

JC


                                                                                                                        
                      "Kalra, Ashwani"                                                                                  
                      <ashwani.kalra@cap        To:       "Struts (E-mail)" <us...@struts.apache.org>                    
                      gemini.com>               cc:                                                                     
                                                Subject:  concurrency problem                                           
                      04/08/2005 06:10                                                                                  
                      AM                                                                                                
                      Please respond to                                                                                 
                      "Struts Users                                                                                     
                      Mailing List"                                                                                     
                                                                                                                        





I am facing concurrency problem in following scenario.


All our action classes call same stateful session bean .  Each action class
obtains the reference  from HTTPSession object and calls one and only one
business method.
To prevent the concurrent access to this instance which occurs when user
immediately presses two links quickly in succession I am using the
following code block




execute(...)  //execute methods of Action class
{
....
....


//Obtain the session from  Request.User will always be in session here
session=request.getSession()
Synchronised(session)
{
    //call ejb's  business method.
}


}


However sometimes  more than one thread is able to pass through, And I get
exception from Appserver. As 2 threads are not allowed for statefull
Session bean.
Can there be problem in above code. Is it ok to synchronise on session
object.









Thanks & Regds
 Ashwani

Ext: 1860









This message contains information that may be privileged or confidential
and is the property of the Capgemini Group. It is intended only for the
person to whom it is addressed. If you are not the intended recipient,  you
are not authorized to read, print, retain, copy, disseminate,  distribute,
or use this message or any part thereof. If you receive this  message in
error, please notify the sender immediately and delete all  copies of this
message.



------------------------------------------------------------------------------
**********
The information contained in this communication is confidential, private, proprietary, or otherwise privileged and is intended only for the use of the addressee.  Unauthorized use, disclosure, distribution or copying is strictly prohibited and may be unlawful.  If you have received this communication in error, please notify the sender immediately at (312)653-6000 in Illinois; (972)766-6900 in Texas; or (800)835-8699 in New Mexico.
**********
==============================================================================


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org