KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > timer > bean > ExampleTimerBean


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.tutorial.timer.bean;
8
9 import java.util.Date JavaDoc;
10 import javax.annotation.Resource;
11 import javax.ejb.Remote JavaDoc;
12 import javax.ejb.SessionContext JavaDoc;
13 import javax.ejb.Stateless JavaDoc;
14 import javax.ejb.Timeout JavaDoc;
15 import javax.ejb.Timer JavaDoc;
16
17 @Stateless JavaDoc
18 @Remote JavaDoc(ExampleTimer.class)
19 public class ExampleTimerBean implements ExampleTimer
20 {
21    private @Resource SessionContext JavaDoc ctx;
22
23    public void scheduleTimer(long milliseconds)
24    {
25       ctx.getTimerService().createTimer(new Date JavaDoc(new Date JavaDoc().getTime() + milliseconds), "Hello World");
26    }
27
28    @Timeout JavaDoc
29    public void timeoutHandler(Timer JavaDoc timer)
30    {
31       System.out.println("---------------------");
32       System.out.println("* Received Timer event: " + timer.getInfo());
33       System.out.println("---------------------");
34
35       timer.cancel();
36    }
37 }
38
Popular Tags