Question 1: As per the book I follow to learn EJB author told that every lookup creates a new stateful session bean. So, what I did is defined a method init() with @PostConstruct annotation with a sysout statement. So, that need to be executed for every Stateful bean instantiated. But the same is not happening. Consider the following code
In Bean
@Stateful
public class PersonnelModelBean implements PersonnelModelRemote{
@PostConstruct
void init(){
System.out.println("STATEFUL BEAN transforming to Mathod Ready state");
}
}
On Client side
try {
InitialContext context = InitialContextBuilder.getJBOSSInitialContext();
PersonnelModelRemote personnelModel = (PersonnelModelRemote)context.lookup("PersonnelModel/remote");
personnelModel.setPersonKey(new Integer(1));
personnelModel.setPersonName("Naresh");
PersonData person = personnelModel.getPerson();
System.out.println(person);
personnelModel = (PersonnelModelRemote)context.lookup("PersonnelModel/remote");
personnelModel.setPersonKey(new Integer(2));
personnelModel.setPersonName("Pokuri");
person = personnelModel.getPerson();
System.out.println(person);
} catch (NamingException e) {
e.printStackTrace();
}
Question 2: In the same way author told that on calling @Remove annotated method would remove client associated bean from container. So, the container has to call destroy()(which is annotated with @PreDestroy) method on deleting bean. But that is not happening. Consider the following code
@Stateful
public class PersonnelModelBean implements PersonnelModelRemote{
@Remove
public PersonData getPerson() {
PersonData personData = new PersonData();
personData.setKey(key);
personData.setName(name);
return personData;
}
@PreDestroy
void destroy(){
System.out.println("STATEFUL BEAN transforming to Does not exist state");
}
}
Question 3: I have set to 60 sec in standardjboss.xml of server/default/conf dir of JBOSS. I have waited for 15 min and on executing the client code it should call @PostConstruct annotated method as told in the book. But that was also not happening.