You can call a Singleton from your EJB Constructor or setContext. This way, your init is called before EJBs are processed.
We use this in our MDB code when a set of external properties have to be loaded before the MDBs start picking messages.
AFAIK, you can't predict when the constructor of an EJB is called wheter the context it is running in (e.g. transactional). And again, a singleton is not a singleton in such an environment.
The proper way to do something like this could be a MBean doing the work and the EJB accessing data from it.
Im not sure what you mean by saying "you cannot predict when constructor is called".
Doesnt the Constructor get called before its moved to the Pooled state?
SEction 10.5.1 of EJB Spec requires that a newInstance and setContext be called before moving it from "Does not Exist" state to "Pooled" state/
the method setXXSessionContext is called before EJB invokation, but I want to execute a method everytime the ear-application is redeployed ...
I'm trying the MBEAN way...
this is true for entity beans. But what are you going to do, when there is a time consuming job to be done before calling a SLSB? ejbCreate() is not called when create is invoked on the home interface. Instead Class.newInstance(), setSessionContext() and ejbCreate() is called when the first method is called on the remote interface.
I think you can configure the jboss pools for your bean, so at least a minimum number of beans is ready and waiting for some action. But this is JBoss configuration done by the deployer.