• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Timers

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

i have few questions on Ejb3 timers, kindly clarify

a)supoose the timer is created for 5min and during that transaction rolled back @ 3rd min(rollback attribute is true), what will happen to timer, will it be recreated on its own? if so what will be the timer expiration, 5min or 2min
b)supoose the timer is created for 5min and suddenly the server crashed @ 3rd min, when server comes up again, what will happen to timer, will it be recreated on own?if so what will be the timer expiration, 5min or 2min


What about nested Timers, some where in the inner loops, runtime exception is thrown, what will be the behaviour

Thanks in advance
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am new to EJB and was reading about Timers for the first time last night.

"Mastering EJBs" says

TIMERS AND TRANSACTIONS
The creation of timers is supported within transactions.
Therefore, if an enterprise bean method that creates the timer is executed as
part of a transaction and if that transaction is rolled back, the timer creation is
rolled back too. Similarly, if an enterprise bean method cancels the timer by
calling cancel() on the Timer interface within a transaction and if that
transaction is rolled back, the container rolls back the timer cancellation as
well. The container restores the duration of the timer to the duration it would
have had, had it not been rolled back.
The timeout callback method can also be called within a transaction and
typically has transaction attributes of REQUIRES or REQUIRES_NEW. Hence, if
the transaction rolls back, the container will call the timeout callback method
again.


which I think answers your first question.

EJB in Action says


However, unlike stateless session beans and MDBs, timers are persistent and can survive a container crash or restart.


which I think answers your second question.
I am unclear however whether you have to explicitly persist the Timer handle or whether the Container is just resiliant in this respect.
A quick test by writing a Timer would prove whether it worked for your Container - have you tried this?

Thanks,

MG
 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whenever the timer is created under any transaction, and that transaction rolls back due to the reasons stated by you, the timer creation will also be rolled back.

But if the timer is already created, and the time is elapsing then at the point of time, when the server crash, upon restart the container must try at least once to call the same timeout callback method with the same time elapse, when it was crashed.
 
I can't take it! You are too smart for me! Here is the tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic