Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Saeed Amer
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Saeed Amer
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic