Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invoking Timer methods from stateful/stateless session bean

 
Vijay Ramalingam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i see that javax.ejb.Timer methods can be called from business methods, afterBegin and beforeCompletion. why it cannot be called from other methods such as setSessionContext, ejbCreate/ejbRemove/ejbActivate/ejbPassivate and afterCompletion in stateful session bean. The specification does not specify the exact condition from where the Timer methods could be invoked from the methods of stateful or stateless session bean.

Could someone please clarify the above?
 
Gaurav Totla
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As par my understading EJB timer service is only applicable to Stateless session beans and MDB's. If you try to invoke getTimerService() for Stateful session bean container will throw an IllegalStateException.

As par specs
"ejb-3_0-fr-spec-ejbcore
Timers cannot be created for stateful session beans[94] or EJB 3.0 entities."
[94] This functionality may be added in a future release of this specification."
 
Vijay Ramalingam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Gaurav,

But my question is invoking methods on Timer API and not calling getTimerService().

For example we could get the javax.ejb.Timer object from the serialized TimerHandle, and then invoke methods on it. As per the spec, the javax.ejb.Timer method invocation is allowed from businessmethod, afterCompletion and beforeCompletion.
My question is why it is restricted in other methods of stateful session bean.
 
Vijay Ramalingam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Gaurav,

But my question is invoking methods on Timer API and not calling getTimerService().

For example we could get the javax.ejb.Timer object from the serialized TimerHandle, and then invoke methods on it. As per the spec, the javax.ejb.Timer method invocation is allowed from businessmethod, afterCompletion and beforeCompletion.
My question is why it is restricted in other methods of stateful session bean.
 
S Bhanage
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As per my understanding,
Timer is an active object which allows you to perform
operations like cancel/getNextTimeout/getTimeRemaining etc.

To operate on these methods, it must be in active transaction.

"setSessionContext/ejbCreate/ejbRemove" are executed in unspecified transaction.
And for stateless session beans and MDBs "ejbActivate/ejbPassivate" does not make
any sense which also are executed in unspecified transaction.

So Timer methods can not be called from these methods.

In case of "afterCompletion", it is related to stateful session bean and also
this method is the last possible method for stateful session bean transaction
hence can not be used for Timer methods.

Hope this is useful to you.

Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic