wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Specific risks of using java.util.Timer in a SessionBean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Specific risks of using java.util.Timer in a SessionBean?" Watch "Specific risks of using java.util.Timer in a SessionBean?" New topic
Author

Specific risks of using java.util.Timer in a SessionBean?

Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Hi there,

I know that java.util.Timer is not supposed to be used in the servlet or
EJB containers (is the recommendation as strong for the servlet
container?). But I'd really like to understand what the specific risks are.

We are using OAS 9i (which supports EJB 2.0 - not 2.1 - and hence we cannot take advantage of EJB TimerService feature offered in EJB 2.1). I am not sure if the details of what I am trying to do will be of any use. All I want to know "what are the specific risks if I use "java.util.Timer"? Or what risk(s) do I face if I do this:

public class MyBean extends TimerTask implements SessionBean

Thanks in advance!
Saeed
[ May 04, 2007: Message edited by: Saeed Amer ]
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

If you spawn new threads(creating a timer is spawning a new thread) from inside an EJB instance, the container will not be able to manage the lifecycle of the bean instance, as, it would not be able to determine when a particular method has finished execution.
Just a question, why, do you want to make your ejb a timer task? Can't you have a timer task seperately and call the session bean from inside the timer task, using local interface? That was just a thought, may be not relevant in the problem you have.


apigee, a better way to API!
Saeed Amer
Ranch Hand

Joined: Jan 20, 2004
Posts: 140
Thank you so much for your response Nitesh!

I just wanted to get some clarification (which I have got now - Thanks!)

Just a question, why, do you want to make your ejb a timer task? Can't you have a timer task seperately and call the session bean from inside the timer task, using local interface? That was just a thought, may be not relevant in the problem you have.


That is precisely what I am going to do.

Thanks again, friend!

Saeed
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Specific risks of using java.util.Timer in a SessionBean?