标签:style blog http color io os 使用 ar java
Jboss EJB默认使用的定时服务是TimerService,TimerService的使用过程较为繁琐,需要使用一个无状态的serviceBean去实现scheduleTimer, timeoutHandler方法,并且要通过外部调用去启动和控制定时器的频率。在使用过程中觉得TimerService定时器非常不好用。因此希望能使用简单好用Quartz来做为服务器的定时器。
1 import javax.ejb.ActivationConfigProperty; 2 import javax.ejb.MessageDriven; 3 import javax.inject.Inject; 4 5 import org.apache.log4j.Logger; 6 import org.jboss.annotation.ejb.ResourceAdapter; 7 import org.quartz.Job; 8 import org.quartz.JobExecutionContext; 9 import org.quartz.JobExecutionException; 10 //@MessageDriven注释指明这是一个消息驱动Bean,并使用@ActivationConfigProperty注释配置消息的各种属性 11 //@ResourceAdapter告诉EJB容器使用哪种ResourceAdapter 12 @MessageDriven(activationConfig = 13 {@ActivationConfigProperty(propertyName = "cronTrigger", propertyValue = "0/2 * * * * ?")}) 14 @ResourceAdapter("quartz-ra.rar") 15 public class AnnotatedQuartzMDBBean implements Job 16 { 17 @Override 18 public void execute(JobExecutionContext arg0) throws JobExecutionException { 19 //定时器执行内容 20 } 21 }
标签:style blog http color io os 使用 ar java
原文地址:http://www.cnblogs.com/pfxiong/p/4024213.html