1 22 package org.jboss.ejb3.test.pool; 23 24 import java.util.Date ; 25 26 import javax.annotation.Resource; 27 import javax.annotation.PreDestroy; 28 import javax.annotation.PostConstruct; 29 import javax.ejb.Remote ; 30 import javax.ejb.SessionContext ; 31 import javax.ejb.Stateless ; 32 import javax.ejb.Timeout ; 33 import javax.ejb.Timer ; 34 35 import org.jboss.annotation.ejb.RemoteBinding; 36 37 @Stateless 38 @Remote (ExampleTimer.class) 39 @RemoteBinding(jndiBinding="ExampleTimer") 40 public class ExampleTimerBean implements ExampleTimer 41 { 42 private static int instanceCount = 0; 43 44 private @Resource SessionContext ctx; 45 46 public void scheduleTimer(long milliseconds) 47 { 48 ctx.getTimerService().createTimer( 49 new Date (new Date ().getTime() + milliseconds), "Hello World"); 50 } 51 52 @Timeout 53 public void timeoutHandler(Timer timer) 54 { 55 timer.cancel(); 56 57 ctx.getTimerService().createTimer(new Date (new Date ().getTime() + 50), 58 "Hello World"); 59 } 60 61 @PostConstruct 62 public void postConstruct() 63 { 64 instanceCount++; 65 System.out.println("New instance: " + instanceCount); 66 } 67 68 @PreDestroy 69 public void preDestroy() 70 { 71 instanceCount++; 72 System.out.println("Instance removed: " + instanceCount); 73 } 74 } 75 | Popular Tags |