views:

73

answers:

1

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.

+1  A: 

Q1 : this should work, the method with the PostConstruct annotation should be called before any other calls reach the SFSB. Does your client work? Maybe the log message goes to server.log

Q2: The method with a remove annotation is called before the container removes the bean from the container-pool. It is not intended to use with business methods. Check http://www.java2s.com/Code/Java/EJB3/RemoveAnnotation.htm

Q3: The clean-up may be delayed depending on your settings in $JBOSS_HOME/server/defalut/conf/standardjboss.xml Check the cache policy settings in this section:

<container-configuration>
      <container-name>Standard Stateful SessionBean</container-name>
      <call-logging>false</call-logging>
... 

Maybe you can force the container to destroy unneeded beans (just for testing) by setting

<container-pool-conf>
        <MaximumSize>1</MaximumSize>
</container-pool-conf>

and use a second client.

stacker
Q1: All logs are getting displayed on eclipse consoleQ2: But, for Stateful beans container won't use the pooling concept.
Pokuri
Q1: maybe you add another System.out in a method that is called for sure to check the other msg is display in eclipses console.Q2: In jboss-4.2.3 I found the configuration of pool size for stateful session beans in standardjboss.xml so I would not assume that these are fake entries.
stacker