• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invoking an EJB Timer

 
Kumar Amit
Ranch Hand
Posts: 103
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
Ay idea how to invoke a EJBTimer (implemented as stateless session bean) daily? In other words how to schedule it?
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this help?
 
Kumar Amit
Ranch Hand
Posts: 103
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran Pai wrote:Does this help?

Thanks Jai and nice article. However this article describes auto timers in ejb 3.1. Since i am using ejb 3.0 for this assignment, i have to create auto timer using it. Any idea how to do with ejb 3.0.

 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EJB3.0 did not have a feature of "auto timers". You had to programatically create the timers via the javax.ejb.TimerService. Here's an example. The client code would have to invoke that method on the bean for the timer to be started and triggered.
 
Kumar Amit
Ranch Hand
Posts: 103
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran Pai wrote:EJB3.0 did not have a feature of "auto timers". You had to programatically create the timers via the javax.ejb.TimerService. Here's an example. The client code would have to invoke that method on the bean for the timer to be started and triggered.
Thanks Jai. I was talking about client code to invoke the method to trigger the timer. What is the best way to invoke the method on the bean which will create/trigger the timer (timerService.createTimer() etc). Should I use Startup servlet that will invoke this startTimer() method on the bean or something else?
 
Mario Kerk
Greenhorn
Posts: 10
Android Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kumar Amit wrote:I was talking about client code to invoke the method to trigger the timer. What is the best way to invoke the method on the bean which will create/trigger the timer (timerService.createTimer() etc). Should I use Startup servlet that will invoke this startTimer() method on the bean or something else?


Here's another example that uses a ServletContextListener to start up a Timer.
However, I also recommend reading this thread as well, because it mentions some of the common "gotchas" to keep in mind when using EJB 3.0 timers.

 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11833
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the SCEA/OCMJEA exams, you do not need to go so deeply into the APIs. You might want to take a higher level view.
 
Mario Kerk
Greenhorn
Posts: 10
Android Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Monkhouse wrote:For the SCEA/OCMJEA exams, you do not need to go so deeply into the APIs. You might want to take a higher level view.


Hi Andrew,
I'm a bit confused by your reply.

Do you mean that it in a SCEA assignment it would not be important to show how a recurring Timer would be initially scheduled as part of the design OR that we should not worry too much about known shortcomings of this feature (such as the ones mentioned in the other thread I referenced)?

Btw, I should note that in real life projects I have only used quartz, because I've read too many posts on the tricks required to set up Timers properly in clusters, but mostly because quartz always fit the bill better in the end.

Nevertheless, for my SCEA assignment I am considering of suggesting the use of a Timer for a simple polling job to avoid having to introduce an external library in the design. But because even my SCEA project is supposed to be deployable in a cluster, I can't help but wonder if I would need to demonstrate that I'm aware of all this... But then again I'm probably over-thinking

 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic