Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » J2EE Pattern »

Re: concurrency problem

abhijeet rai

2005-04-08


Hi Ashwani,

please read below from the EJB spec 2.0 which is old
spec version --

============
EJB 2.0 spec
============
"[6.5.6] Serializing session bean methods
A container serializes calls to each session bean
instance.Most containers will support many instances
of a session bean executing concurrently; however,
each instance sees only a serialized sequence of
method calls. Therefore a session bean does not have
to be coded as reentrant.

The container must serialize all the container-invoked
callbacks (ejbPassivate, beforeCompletion, ...)

Clients are not allowed to make concurrent calls to a
SFSB(Stateful Session Bean).The container must throw a
java.rmi.Exception to the second client.This
restriction does not apply to SLSB(Stateless Session
Bean)."

Please check EJB spec 2.1 if you are using it and
confirm whether this is still valid.

Hope this helps.

Cheers
Abhijeet
BEA Support Engineer

--- "Kalra, Ashwani" <ashwani.kalra@(protected)>
wrote:
>
> 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.
>
>
====================================================================
> Companion Site: http://www.corej2eepatterns.com
> J2EE BluePrints:
> http://java.sun.com/blueprints/corej2eepatterns
> List Archive:
>
http://archives.java.sun.com/archives/j2eepatterns-interest.html
> Unsubscribing: email "signoff J2EEPATTERNS-INTEREST"
> to listserv@(protected)
>



__________________________________
Do you Yahoo!?
Yahoo! Mail - 250MB free storage. Do more. Manage less.
http://info.mail.yahoo.com/mail_250

====================================================================
Companion Site: http://www.corej2eepatterns.com
J2EE BluePrints: http://java.sun.com/blueprints/corej2eepatterns
List Archive: http://archives.java.sun.com/archives/j2eepatterns-interest.html
Unsubscribing: email "signoff J2EEPATTERNS-INTEREST" to listserv@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.