简体   繁体   English

EJB Schedule在Weblogic上自动启动

[英]EJB Schedule automatic start on weblogic

I currently have an EJB that has an @ schedule that runs every 5 minutes, but I only run after the ejb initialized. 我目前有一个EJB,它的@调度每5分钟运行一次,但是我只在初始化ejb之后运行。

the question is whether you can make the timer starts running after deployment and do not wait until there is an invocation to the EJB for starting. 问题是,是否可以使计时器在部署后开始运行,而不要等到对EJB的调用才能启动后才开始。

Here is my code: 这是我的代码:

@Remote(ServiceRemote.class)
@Stateless(mappedName = "ejb/ServiceEJBSL")
public class ServiceBean implements ServiceRemote {
@Schedule(second="*", minute="*/5", hour="*", dayOfWeek="0-6")
public void autmaticTimer() throws Exception, RemoteException{
System.out.println("do something");
}
}

I did this in glasfish server but it seems doesnt work the same way. 我在glasfish服务器中执行了此操作,但似乎无法以相同的方式工作。

Thanks in advance. 提前致谢。

You'll need GlassFish v3.+ because this feature was added in EJB 3.1 您将需要GlassFish v3。+,因为EJB 3.1中已添加了此功能

Automatic timers are created by the EJB container when an enterprise bean that contains methods annotated with the @Schedule or @Schedules annotations is deployed. 部署包含以@Schedule@Schedules批注进行批注的方法的企业bean时,EJB容器会创建自动计时器。

@Schedule(minute="*/5", hour="*")
public void automaticTimer() throws Exception, RemoteException{
   System.out.println("do something");
}

Addition 加成

Try to add 尝试添加

@Schedule(minute="*/5", hour="*", persistent=false)

Because persistent timers are not re-created if already existing when keepstate is set to true . 因为在keepstate设置为true持久计时器不会重新创建(如果已经存在)。

See 看到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM