1 7 package org.jboss.tutorial.timer.bean; 8 9 import java.util.Date ; 10 import javax.annotation.Resource; 11 import javax.ejb.Remote ; 12 import javax.ejb.SessionContext ; 13 import javax.ejb.Stateless ; 14 import javax.ejb.Timeout ; 15 import javax.ejb.Timer ; 16 17 @Stateless 18 @Remote (ExampleTimer.class) 19 public class ExampleTimerBean implements ExampleTimer 20 { 21 private @Resource SessionContext ctx; 22 23 public void scheduleTimer(long milliseconds) 24 { 25 ctx.getTimerService().createTimer(new Date (new Date ().getTime() + milliseconds), "Hello World"); 26 } 27 28 @Timeout 29 public void timeoutHandler(Timer 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 |