1 6 package org.jfox.examples.ejb.timer; 7 8 import javax.ejb.CreateException ; 9 import javax.ejb.EJBException ; 10 import javax.ejb.SessionBean ; 11 import javax.ejb.SessionContext ; 12 import javax.ejb.TimedObject ; 13 import javax.ejb.Timer ; 14 import javax.ejb.TimerHandle ; 15 import javax.ejb.TimerService ; 16 17 20 21 public class TestTimerBean implements SessionBean , TimedObject { 22 private SessionContext context; 23 24 public TestTimerBean() { 25 } 26 27 public void setSessionContext(SessionContext sessionContext) throws EJBException { 28 context = sessionContext; 29 } 30 31 public void ejbRemove() throws EJBException { 32 } 33 34 public void ejbActivate() throws EJBException { 35 } 36 37 public void ejbPassivate() throws EJBException { 38 } 39 40 public void ejbCreate() throws CreateException { 41 } 42 43 public void ejbTimeout(Timer timer) { 44 System.out.println("ejbTimeout, Timer is: " + timer); 45 46 TimerHandle handle = timer.getHandle(); 47 System.out.println("TimerHandler: " + handle); 48 49 System.out.println("Timer get by TimerHandler: " + handle.getTimer()); 50 } 51 52 public void shedule(long time) { 53 TimerService timerService = context.getTimerService(); 54 timerService.createTimer(time, null); 55 } 56 } 57 | Popular Tags |