hi,
Firtst of all i wan2 let u kno that the discussion is abt SFSB since for SLSB each method invocation is a new REQ to the container and wil b(may b) handled by the new instance.
Firstly, HF EJB says that we are not supposed to write any thread related code such as synchronized, wait, notify, Thread class...To be frank with you I laughed in my mind "Ohoh! So, I can escape from thread codes in EJB, hurrah!!!".....But then ur code made me sit up and see whatz that thread code inside SB.
U can write thread based pgms using EJB but not withing UR bean class but in client code.
Secondly, SB does not know whether business methods call from client through the body guard(EJBObject) is coming from one or two windows. Both methods are from same client AFTER ALL!!!
Yes U R right.
It is as good as calling "add an item" to cart first and the calling "remove the item" from cart from a single window.
No U r wrong , V R talking abt concurrent invocation of methods. Here in this case if U r in txn of "add an item" to cart and if u call "remove the item" container will thro RemoveExc..n
And I dont know how container will handle, if in case these method calls are going simultaneously from two windows from a single client. I want to avoid thread codes as HF says, haa....
Contianre wil throw RemoteExce..n or EJBExce..n
To achieve same result U can create threads in client code.
Stateful bean can leave a tx open in a method. If a client calls a method from stateful bean which opens a tx and then calls a method which does not use same tx, error will be thrown. Bcos, opened tx is not yet commited/rolled back. But client is trying to use some other tx. This is my humble opinion.
Yes U R right.But V r not discussing abt that. V R talking abt the folowing sentence from EJB 2.0 spec.:
If SB instance is participating in a Txn , its an err for a client to invoke a method on SB instance such that the txn attrribute in DD wud cause
container to execute the method in difrent txn ctx or in unspecified txn ctx....
In order understand this scenario consider following code snippet:
(1)@ ur client side u have folowin classes
import x.y.z......
.......
public class MyThread1 implements Runnable{
MyCompObj obj =null;
............................
public MyThread(){}
public MyThread(Object obj){
obj =(MyCompObj)obj;
}
public void run(){
obj.bizMthod1();
}
}
public class MyThread2 implements Runnable{
MyCompObj obj =null;
............................
public MyThread(){}
public MyThread(Object obj){
obj =(MyCompObj)obj;
}
public void run(){
obj.bizMthod2();
}
}
*****************************************************************
(2)in ur ejb-jar.xml
<ejb-jar>
<enterprise-beans>
....................
...........................
<enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>MBean</ejb-name>
<method-name>bizMthod1</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
<container-transaction>
<method>
<ejb-name>Bean1</ejb-name>
<method-name>bizMthod2</method-name>
</method>
<trans-attribute>RequiresNew</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
*****************************************************************
(3) in UR client pgm u have
EJBObject sharedObj = getEJBObjectFromHome(); // getting UR componet intf obj from Home obj
MyThread1 t1 = new MyThread1(sharedObj);
MyThread2 t2 = new MyThread2(sharedObj);
t1.start(); // This will cause container to execute bizMthod1 and SB instance is associating in a Txn with txn attr Required
t2.start(); // with this txn attr in DD is causing container to execute 2nd method in difrent txn
In this scenario container wil thro RemoteExc..n (Remote Client)or EJBExc..n(Local client) back to the client....
thanx & rgds
Binoj V