• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Confusion in call back methods

 
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


@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
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

@Remove (Remove session with client, instance back to pool)
@PreDestroy (Instance Destroyed from Memory.)

Order should be

@Remove
@PreDestroy

Right?
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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).
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic