Re: AW: Synchronizing ejb method

"Kalra, Ashwani" <[email protected]> Fri, 19 May 2006 09:45:47 +0530
Newsgroups gmane.comp.java.sun.ejb.general
Message-ID <1B0CECCD25CA24499E03717EF3D503F10273CA01@BOMEX001.corp.capgemini.com>
This is a multi-part message in MIME format.

------_=_NextPart_001_01C67AFA.C8E29114
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


No its not correct=2E=20
Section 7=2E5=2E8 , Ejb 2=2E1
=20
"Clients are not allowed to make concurrent calls to a stateful session=
 object=2E If a client-invoked business

method is in progress on an instance when another client-invoked call, from=
 the same or different client,

arrives at the same instance of a stateful session bean class, the=
 container may throw the

java=2Ermi=2ERemoteException to the second client[7] if the client is a=
 remote client, or the

javax=2Eejb=2EEJBException if the client is a local client=2E This=
 restriction does not apply to a stateless

session bean because the container routes each request to a different=
 instance of the session bean

class=2E"

I think there is no standard approach as Andreas said=2E My problem is that=
 there is some batch process running and there is jsp page that can access=
 the same method of ejb which I wanted to avoid=2E I think I can use=
 statefull session bean so that at least second client gets the exception=
=2E

=20

Thanks

Ashwani

=20

=20


________________________________

From: A mailing list for Enterprise JavaBeans development=
 [mailto:EJB-INTEREST@JAVA=2ESUN=2ECOM] On Behalf Of Tareq Ayub
Sent: Friday, May 19, 2006 7:55 AM
To: EJB-INTEREST@JAVA=2ESUN=2ECOM
Subject: Re: AW: Synchronizing ejb method


Refer to the EJB spec=2E The container will not allow multiple threads to=
 use the same instance of an SLSB=2E From the spec - "The container must=
 ensure that only one thread can be executing an instance at any time"=2E=
 Given that, why would you want to synchronize on an EJB method anyways ?=
 Also, SLSB have no state (no instance variables)=2E  The same principle=
 applies to SFSB in addition to the fact an instance is tied to a single=
 client=2E=20

Tareq=20


On May 15, 2006, at 2:40 AM, Andreas Berg wrote:


        You shouldn't=2E The only reason to synchronize a stateless session bean=
 is if your bean is not stateless=2E Then ask yourself why you chose a=
 stateless bean for some stateful purpose=2E
        =20
        If you really want to synchronize your SLSB you need to think about the=
 runtime environment=2E If all the instances of the SLSB run in a single=
 JVM, you can use the standard Java synchronization features inside the=
 bean to synchronize=2E But this doesn't work with a clustered environment=
=2E AFAIK there is no standard approach to solve this=2E
        =20
        Kind regards,
        =20
        Andreas=2E
        =20
        =20
        Andreas Berg
        Zelfi AG
        Hechtsheimer Stra=DFe 33
        55131 Mainz
        Telefon: 06131-9064850
        Telefax: 06131-9064853
        andreas=2Eberg@zelfi=2Ecom
        http://www=2Ezelfi=2Ecom/
        =20

________________________________

        Von: A mailing list for Enterprise JavaBeans development=
 [mailto:EJB-INTEREST@JAVA=2ESUN=2ECOM] Im Auftrag von Kalra, Ashwani
        Gesendet: Montag, 15=2E Mai 2006 06:42
        An: EJB-INTEREST@JAVA=2ESUN=2ECOM
        Betreff: Synchronizing ejb method
=09
=09
        Hi,
        The client of my ejb can be an jsp or standalone java class=2E  How can I=
 synchronize access to the SLSB ejb method? I am using ejb2=2E0 version
        =20
        =20

        __________________=20
        Regards=20
        Ashwani Kalra=20
=09

        =20
This message contains information that may be privileged or confidential=
 and is the property of the Capgemini Group=2E It is intended only for the=
 person to whom it is addressed=2E 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=2E If you receive this=
 message in error, please notify the sender immediately and delete all=
 copies of this message=2E

=09
        =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D To unsubscribe, send email to listserv@java=2Esun=2Ecom and include in=
 the body of the message "signoff EJB-INTEREST"=2E For general help, send=
 email to listserv@java=2Esun=2Ecom and include in the body of the message=
 "help"=2E=20

        =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D To unsubscribe, send email to listserv@java=2Esun=2Ecom and include in=
 the body of the message "signoff EJB-INTEREST"=2E For general help, send=
 email to listserv@java=2Esun=2Ecom and include in the body of the message=
 "help"=2E=20



=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 To unsubscribe, send email to listserv@java=2Esun=2Ecom and include in the=
 body of the message "signoff EJB-INTEREST"=2E For general help, send email=
 to listserv@java=2Esun=2Ecom and include in the body of the message "help"=
=2E=20



This message contains information that may be privileged or confidential=
 and is the property of the Capgemini Group=2E It is intended only for the=
 person to whom it is addressed=2E 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=2E If you receive this=
  message in error, please notify the sender immediately and delete all =
 copies of this message=2E

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[email protected] and include in the body of the message "help".


------_=_NextPart_001_01C67AFA.C8E29114
Content-Type: text/html;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4=2E0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=
=3Diso-8859-1">
<META content=3D"MSHTML 6=2E00=2E2900=2E2873" name=3DGENERATOR></HEAD>
<BODY=20
style=3D"WORD-WRAP: break-word; khtml-nbsp-mode: space; khtml-line-break:=
 after-white-space">
<DIV dir=3Dltr align=3Dleft><SPAN class=3D734250804-19052006><FONT face=
=3DArial=20
color=3D#0000ff size=3D2>No its not correct=2E </FONT></SPAN></DIV>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D734250804-19052006><FONT face=
=3DArial=20
color=3D#0000ff size=3D2>Section 7=2E5=2E8 , Ejb 2=2E1</FONT></SPAN></DIV>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D734250804-19052006><FONT face=
=3DArial=20
color=3D#0000ff size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV dir=3Dltr align=3Dleft><SPAN class=3D734250804-19052006><FONT size=
=3D2><SPAN=20
class=3D734250804-19052006>"</SPAN>Clients are not allowed to make=
 concurrent=20
calls to a <STRONG>stateful session object</STRONG>=2E If a client-invoked=
=20
business</FONT></DIV>
<DIV dir=3Dltr align=3Dleft>
<P align=3Dleft><FONT size=3D2>method is in progress on an instance when=
 another=20
client-invoked call, from the same or different client,</FONT></P>
<P align=3Dleft><FONT size=3D2>arrives at the same instance of a stateful=
 session=20
bean class, the container may throw the</FONT></P><FONT face=3DCourier size=
=3D2>
<P align=3Dleft>java=2Ermi=2ERemoteException </FONT><FONT face=3D"Times New=
 Roman"=20
size=3D2>to the second client</FONT><FONT face=3D"Times New Roman" size=
=3D1>[7]=20
</FONT><FONT face=3D"Times New Roman" size=3D2>if the client is a remote=
 client, or=20
the</P></FONT><FONT face=3DCourier size=3D2>
<P align=3Dleft>javax=2Eejb=2EEJBException </FONT><FONT size=3D2>if the=
 client is a=20
local client=2E This restriction does not apply to a stateless</FONT></P>
<P align=3Dleft><FONT size=3D2>session bean because the container routes=
 each=20
request to a different instance of the session bean</FONT></P>
<P align=3Dleft><FONT size=3D2>class=2E<SPAN=20
class=3D734250804-19052006>"</SPAN></FONT></P>
<P align=3Dleft><SPAN class=3D734250804-19052006><FONT size=3D2><FONT face=
=3DArial=20
color=3D#0000ff>I think there is no standard approach as Andreas said=2E My=
 problem=20
is that there is some batch process running and there is jsp page that can=
=20
access the same method of ejb which I wanted to avoid</FONT>=2E <FONT face=
=3DArial=20
color=3D#0000ff>I think I can use statefull session bean so that at least=
 second=20
client gets the exception=2E</FONT></FONT></SPAN></P>
<P align=3Dleft><SPAN class=3D734250804-19052006><FONT face=3DArial color=
=3D#0000ff=20
size=3D2></FONT></SPAN>&nbsp;</P>
<P align=3Dleft><SPAN class=3D734250804-19052006><FONT face=3DArial color=
=3D#0000ff=20
size=3D2>Thanks</FONT></SPAN></P>
<P align=3Dleft><SPAN class=3D734250804-19052006><FONT face=3DArial color=
=3D#0000ff=20
size=3D2>Ashwani</FONT></SPAN></P>
<P align=3Dleft><SPAN class=3D734250804-19052006><FONT face=3DArial color=
=3D#0000ff=20
size=3D2></FONT></SPAN>&nbsp;</P>
<P align=3Dleft><FONT size=3D2><SPAN=20
class=3D734250804-19052006></SPAN></FONT>&nbsp;</P></SPAN></DIV><BR>
<DIV class=3DOutlookMessageHeader lang=3Den-us dir=3Dltr align=3Dleft>
<HR tabIndex=3D-1>
<FONT face=3DTahoma size=3D2><B>From:</B> A mailing list for Enterprise=
 JavaBeans=20
development [mailto:EJB-INTEREST@JAVA=2ESUN=2ECOM] <B>On Behalf Of=
 </B>Tareq=20
Ayub<BR><B>Sent:</B> Friday, May 19, 2006 7:55 AM<BR><B>To:</B>=20
EJB-INTEREST@JAVA=2ESUN=2ECOM<BR><B>Subject:</B> Re: AW: Synchronizing ejb=
=20
method<BR></FONT><BR></DIV>
<DIV></DIV>Refer to the EJB spec=2E The container will not allow multiple=
 threads=20
to use the same instance of an SLSB=2E From the spec - "<FONT=20
class=3DApple-style-span face=3DVerdana size=3D3><SPAN class=
=3DApple-style-span=20
style=3D"FONT-SIZE: 13px">The container must ensure that only one thread=
 can be=20
executing an instance at any time"=2E Given that, why would you want to=20
synchronize on an EJB method anyways ? Also, SLSB have no state (no=
 instance=20
variables)=2E&nbsp; The same principle applies to SFSB in addition to the=
 fact an=20
instance is tied to a single client=2E</SPAN></FONT>
<DIV><BR class=3Dkhtml-block-placeholder></DIV>
<DIV><FONT class=3DApple-style-span face=3DVerdana size=3D3><SPAN=20
class=3DApple-style-span style=3D"FONT-SIZE: 13px"></SPAN></FONT>Tareq
<DIV><FONT class=3DApple-style-span face=3DVerdana size=3D3><SPAN=20
class=3DApple-style-span style=3D"FONT-SIZE: 13px"><BR></SPAN></FONT>
<DIV>
<DIV>On May 15, 2006, at 2:40 AM, Andreas Berg wrote:</DIV><BR=20
class=3DApple-interchange-newline>
<BLOCKQUOTE type=3D"cite">
  <DIV dir=3Dltr align=3Dleft><FONT face=3DArial color=3D#0000ff size=
=3D2><SPAN=20
  class=3D265003407-15052006>You shouldn't=2E&nbsp;The only reason&nbsp;to=
=20
  synchronize a stateless session bean is if your bean is not stateless=2E=
 Then=20
  ask yourself why you chose a stateless bean for some stateful=20
  purpose=2E</SPAN></FONT></DIV>
  <DIV dir=3Dltr align=3Dleft><FONT face=3DArial color=3D#0000ff size=
=3D2><SPAN=20
  class=3D265003407-15052006></SPAN></FONT>&nbsp;</DIV>
  <DIV dir=3Dltr align=3Dleft><FONT face=3DArial color=3D#0000ff size=
=3D2><SPAN=20
  class=3D265003407-15052006>If you really want to synchronize your SLSB=
 you need=20
  to think about the runtime environment=2E If all the instances of the=
 SLSB run=20
  in a single JVM, you can use the standard Java synchronization features=
 inside=20
  the bean to synchronize=2E But this doesn't work with a clustered=
 environment=2E=20
  AFAIK there is no standard approach to solve this=2E</SPAN></FONT></DIV>
  <DIV dir=3Dltr align=3Dleft><FONT face=3DArial color=3D#0000ff size=
=3D2><SPAN=20
  class=3D265003407-15052006></SPAN></FONT>&nbsp;</DIV>
  <DIV dir=3Dltr align=3Dleft><FONT face=3DArial color=3D#0000ff size=
=3D2><SPAN=20
  class=3D265003407-15052006>Kind regards,</SPAN></FONT></DIV>
  <DIV dir=3Dltr align=3Dleft><FONT face=3DArial color=3D#0000ff size=
=3D2><SPAN=20
  class=3D265003407-15052006></SPAN></FONT>&nbsp;</DIV>
  <DIV dir=3Dltr align=3Dleft><FONT face=3DArial color=3D#0000ff size=
=3D2><SPAN=20
  class=3D265003407-15052006>Andreas=2E</SPAN></FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV align=3Dleft><FONT face=3DArial color=3D#000000 size=
=3D2></FONT>&nbsp;</DIV>
  <DIV align=3Dleft><FONT face=3DArial color=3D#808000 size=3D1>Andreas=
 Berg<BR>Zelfi=20
  AG<BR>Hechtsheimer Stra=DFe 33<BR>55131 Mainz<BR>Telefon:=20
  06131-9064850<BR>Telefax:&nbsp;06131-9064853</FONT></DIV>
  <DIV align=3Dleft><FONT face=3DArial color=3D#808000 size=3D1><A=20
  href=3D"mailto:andreas=2Eberg@zelfi=2Ecom">andreas=2Eberg@zelfi=
=2Ecom</A></FONT></DIV>
  <DIV align=3Dleft><FONT face=3DArial color=3D#808000 size=3D1><A=20
  href=3D"http://www=2Ezelfi=2Ecom/">http://www=2Ezelfi=
=2Ecom/</A></FONT></DIV>
  <DIV>&nbsp;</DIV><BR>
  <DIV class=3DOutlookMessageHeader lang=3Dde dir=3Dltr align=3Dleft>
  <HR tabIndex=3D-1>
  <FONT face=3DTahoma size=3D2><B>Von:</B> A mailing list for Enterprise=
 JavaBeans=20
  development [<A=20
  href=3D"mailto:EJB-INTEREST@JAVA=2ESUN=2ECOM">mailto:EJB-INTEREST@JAVA=
=2ESUN=2ECOM</A>]=20
  <B>Im Auftrag von </B>Kalra, Ashwani<BR><B>Gesendet:</B> Montag, 15=2E=
 Mai 2006=20
  06:42<BR><B>An:</B> <A=20
  href=3D"mailto:EJB-INTEREST@JAVA=2ESUN=2ECOM">EJB-INTEREST@JAVA=2ESUN=
=2ECOM</A><BR><B>Betreff:</B>=20
  Synchronizing ejb method<BR></FONT><BR></DIV>
  <DIV></DIV>
  <DIV><SPAN class=3D087493904-15052006><FONT face=3DArial=20
  size=3D2>Hi,</FONT></SPAN></DIV>
  <DIV><SPAN class=3D087493904-15052006><FONT face=3DArial size=3D2>The=
 client of my=20
  ejb can be an jsp or standalone java class=2E&nbsp; How can I synchronize=
 access=20
  to the SLSB ejb method? I am using ejb2=2E0 version</FONT></SPAN></DIV>
  <DIV><SPAN class=3D087493904-15052006><FONT face=3DArial=20
  size=3D2></FONT></SPAN>&nbsp;</DIV>
  <DIV>&nbsp;</DIV>
  <P><SPAN lang=3Den-us><FONT face=3DArial size=
=3D2>__________________</FONT></SPAN>=20
  <BR><SPAN lang=3Den-us><FONT face=3DTahoma size=3D2>Regards</FONT></SPAN>=
 <BR><SPAN=20
  lang=3Den-us><B><FONT face=3DTahoma size=3D2>Ashwani=
 Kalra</FONT></B></SPAN>=20
<BR></P>
  <DIV>&nbsp;</DIV>
  <TABLE>
    <TBODY>
    <TR>
      <TD bgColor=3D#ffffff><FONT color=3D#000000>This message contains=20
        information that may be privileged or confidential and is the=
 property=20
        of the Capgemini Group=2E It is intended only for the person to=
 whom it is=20
        addressed=2E If you are not the intended recipient, you are not=
 authorized=20
        to read, print, retain, copy, disseminate, distribute, or use this=
=20
        message or any part thereof=2E If you receive this message in=
 error,=20
        please notify the sender immediately and delete all copies of this=
=20
        message=2E<BR><BR></FONT></TD></TR></TBODY></TABLE>=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=20
  To unsubscribe, send email to <A=20
  href=3D"mailto:listserv@java=2Esun=2Ecom">listserv@java=2Esun=2Ecom</A>=
 and include in=20
  the body of the message "signoff EJB-INTEREST"=2E For general help, send=
 email=20
  to <A href=3D"mailto:listserv@java=2Esun=2Ecom">listserv@java=2Esun=
=2Ecom</A> and=20
  include in the body of the message "help"=2E=20
  <DIV><BR=20
  class=3Dkhtml-block-placeholder></DIV>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=20
  To unsubscribe, send email to <A=20
  href=3D"mailto:listserv@java=2Esun=2Ecom">listserv@java=2Esun=2Ecom</A>=
 and include in=20
  the body of the message "signoff EJB-INTEREST"=2E For general help, send=
 email=20
  to <A href=3D"mailto:listserv@java=2Esun=2Ecom">listserv@java=2Esun=
=2Ecom</A> and=20
  include in the body of the message "help"=2E=20
  <DIV><BR=20
class=3Dkhtml-block-placeholder></DIV></BLOCKQUOTE></DIV><BR></DIV></DIV>=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=20
To unsubscribe, send email to listserv@java=2Esun=2Ecom and include in the=
 body of=20
the message "signoff EJB-INTEREST"=2E For general help, send email to=20
listserv@java=2Esun=2Ecom and include in the body of the message "help"=2E=
=20
<P></P></BODY></HTML>

<table><tr><td bgcolor=3D#ffffff><font color=3D#000000>This message=
 contains information that may be privileged or confidential and is the=
 property of the Capgemini Group=2E It is intended only for the person to=
 whom it is addressed=2E 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=2E If you receive this  message in=
 error, please notify the sender immediately and delete all  copies of this=
 message=2E<br>
<br>
</font></td></tr></table>
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[email protected] and include in the body of the message "help".
<p>
------_=_NextPart_001_01C67AFA.C8E29114--