| Author |
Confusion in call back methods
|
Gowher Naik
Ranch Hand
Joined: Feb 07, 2005
Posts: 643
|
|
@Stateful(name="mySessionBean") public class SessionBean implements SessionRemote { @PostConstruct //ejbCreate() public void init(){ System.out.println("init called"); } //business method public void getResult() { System.out.println("getResult called"); } @PreDestroy public void cleanup()throws Exception{ System.out.println("cleanup called"); } @PostActivate //ejbActivate() public void activate(){ System.out.println("activate called"); } @PrePassivate //ejbPassivate() public void passivate()throws Exception{ System.out.println("passivate called"); } @Remove //ejbRemove() public void remove(){ System.out.println("remove called"); } } @Remote public interface SessionRemote { void getResult(); void remove(); } //Client public static void main( String[] args)throws Exception { sessionBean.getResult(); sessionBean.remove(); }
I have EJB2 background.In above code i am not able to find difference between PreDestroy and Remove callback methods. Output of this bean is as follows init called getResult called remove called cleanup called According me the remove method should be called as last method i.e output should be as follows init called getResult called cleanup called remove called Thanks
|
 |
Tushar Roy
Greenhorn
Joined: Mar 26, 2008
Posts: 29
|
|
|
remove is the method called by the client program when you dont need the stateful bean anymore...Once you call the remove method the container knows it has to discard the bean...at that point it calls the predestroy method to perform cleanup...So predestroy method will be called after remove method...
|
Tushar<br /> <br />SCJP 5 (95%)<br />SCWCD 1.4 (92%)<br />SCBCD 5 (93%)
|
 |
Gowher Naik
Ranch Hand
Joined: Feb 07, 2005
Posts: 643
|
|
Thanks for reply According to me the purpose of PreDestroy method is that do some activity before destroying or removing bean instance.So PreDestroy should be called before Remove method. What is purpose of calling PreDestroy method when bean is already removed.
|
 |
Tushar Roy
Greenhorn
Joined: Mar 26, 2008
Posts: 29
|
|
|
Purpose of pre-destroy is to perform cleanup operations. Its not to remove the bean. The bean is removed by the container when you call @Remove annotated method.Pre-destroy is just a callback listener method called before the bean is destroyed. @Remove is the method you call to indicate the container that you want the bean to be removed. So always the remove method will be called before pre destory method.
|
 |
Ram Venkat
Greenhorn
Joined: Nov 28, 2007
Posts: 29
|
|
Hi all, @Remove (Remove session with client, instance back to pool) @PreDestroy (Instance Destroyed from Memory.) Order should be @Remove @PreDestroy Right?
|
Ram Venkat<br />----------<br />SCJP 1.4<br />SCWCD 1.4<br />SCBCD 5 (In Process..)
|
 |
Uchana Jackson
Ranch Hand
Joined: Dec 07, 2007
Posts: 37
|
|
"The Remove annotation may be used to annotate a stateful session bean business method. Use of this annotation will cause the container to remove the stateful session bean instance after the completion (normal or abnormal) of the annotated method." source: JSR220-simplified In EJB3, @Remove only applies to SFSB, not SLSB. There is no method-ready pool for SFSB's (SFSB's hold client-specific data).
|
SCJP 1.4<br />SCBCD 5
|
 |
Narendra Dhande
Ranch Hand
Joined: Dec 04, 2004
Posts: 950
|
|
Hi, The method annotated with @Remove is business method. The client must call this method to indicate that the client want to remove the steteful session bean. The container only know after the remove method is called the client want to remove the instance. after this the container will do the cleanup work in the preDestroy method. Thanks
|
Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
|
 |
 |
|
|
subject: Confusion in call back methods
|
|
|