You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by "Jay D. McHugh" <ja...@jnwd.net> on 2008/04/10 21:27:23 UTC

EJB3 Timer Beans

Hello all.

I have been using annotated stateless session timer beans with the 
number of milliseconds until they expire.  This has been working fine.

Today, I tried to change over from expiring after a duration to expiring 
at a particular date/time.  But now, the timers are not expiring.

Here is an example of how I was setting timers (worked):

    long oneHour = 60 * 60 * 1000;
    String info = "after five seconds, and each hour after";

    timerService.createTimer(5000, oneHour, info);

Here is an example of what I changed it to (not working):

    long oneHour = 60 * 60 * 1000;
    String info = "on the next hour, and ever hour after";

    Calendar now = Calendar.getInstance();
    now.add(Calendar.HOUR, 1);
    now.set(Calendar.MINUTE, 0);

    timerService.createTimer(now.getTime(), oneHour, info);

Can anyone see a problem with what I changed?


Thanks,

Jay


Re: EJB3 Timer Beans

Posted by Dain Sundstrom <da...@iq80.com>.
On Apr 10, 2008, at 12:27 PM, Jay D. McHugh wrote:
> Hello all.
>
> I have been using annotated stateless session timer beans with the  
> number of milliseconds until they expire.  This has been working fine.
>
> Today, I tried to change over from expiring after a duration to  
> expiring at a particular date/time.  But now, the timers are not  
> expiring.
>
> Here is an example of how I was setting timers (worked):
>
>   long oneHour = 60 * 60 * 1000;
>   String info = "after five seconds, and each hour after";
>
>   timerService.createTimer(5000, oneHour, info);
>
> Here is an example of what I changed it to (not working):
>
>   long oneHour = 60 * 60 * 1000;
>   String info = "on the next hour, and ever hour after";
>
>   Calendar now = Calendar.getInstance();
>   now.add(Calendar.HOUR, 1);
>   now.set(Calendar.MINUTE, 0);
>
>   timerService.createTimer(now.getTime(), oneHour, info);

Your calendar math looks correct (I tested that since is is what I  
always get wrong), and the createTimer call seems to be correct.

> Can anyone see a problem with what I changed?

Everything seems correct.  Looking at the code for the  
createTimer(long initialDuration, long intervalDuration, Serializable  
info) simply calls createTimer(new Date(System.currentTimeMillis() +  
initialDuration), intervalDuration, info), so I don't see how one  
would work and the other wouldn't.

One possibility is if somewhere in your changes, you added some code  
that causes a transaction rollback, then the timer task is "rolled  
back", which means it is never started or registered.

-dain