是否可以在应用程序代码之外配置EJB 3.1 @Schedule? [英] Can the EJB 3.1 @Schedule be configured outside of the application code?
本文介绍了是否可以在应用程序代码之外配置EJB 3.1 @Schedule?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何配置计划间隔:
@Schedule(persistent = true,minute =*,second =* / 5,小时=*)
在应用程序代码之外?
- 如何在ejb-jar.xml中配置它?
- 我可以在应用程序之外配置它(属性文件的种类)吗?
推荐答案
以下是部署描述符中的调度示例:
Here is an example of a scheduling in the deployment descriptor:
<session>
<ejb-name>MessageService</ejb-name>
<local-bean/>
<ejb-class>ejb.MessageService</ejb-class>
<session-type>Stateless</session-type>
<timer>
<schedule>
<second>0/18</second>
<minute>*</minute>
<hour>*</hour>
</schedule>
<timeout-method>
<method-name>showMessage</method-name>
</timeout-method>
</timer>
</session>
配置计时器的另一种方法是使用程序化计划。
Another way of configuring timers is with a programmatic scheduling.
@Singleton
@Startup
public class TimedBean{
@Resource
private TimerService service;
@PostConstruct
public void init(){
ScheduleExpression exp=new ScheduleExpression();
exp.hour("*")
.minute("*")
.second("*/10");
service.createCalendarTimer(exp);
}
@Timeout
public void timeOut(){
System.out.println(new Date());
System.out.println("time out");
}
}
这篇关于是否可以在应用程序代码之外配置EJB 3.1 @Schedule?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文