简体   繁体   English

清除EJB中@Schedule的缓存

[英]Clear cache of @Schedule in EJB

I have a singleton class that perform an task in some time interval. 我有一个单例课程,可以在一定时间间隔内执行任务。 When the application starts its all fine, the task is run in right period and that interval is enough suck that any task isn't overlap. 当应用程序开始正常运行时,任务将在适当的时间段内运行,并且该间隔足够长,以至于任何任务都不会重叠。

The class is show bellow: 班级如下所示:

@Singleton
@Startup
public class BOTAnalisaSituacao {
    public BOTAnalisaSituacao() throws FileNotFoundException {
    }

    @Schedule(second = "0", minute = "*/1", hour = "*")
    public void analisar() throws Exception {
        System.out.println("Starting");
        System.out.println("DONE");
    }
 }

The web container used is Wildfly 10. 使用的Web容器是Wildfly 10。

The problem is, when the application is started after one hour down, for example, the task is executed sequentially, in this case all 60 calls, after that the 1 minute period is restored by itself. 问题是,例如,当应用程序在停机一小时后启动时,该任务将按顺序执行,在这种情况下,将全部执行60次调用,此后将自动恢复1分钟的时间。 Do I have to clear any cache to avoid suck behavior? 我是否必须清除任何缓存,以免发生吮吸行为?

Timers are persistent by default. 默认情况下,计时器是持久性的。 If the server is shut down or crashes, persistent timers are saved and will become active again when the server is restarted, If a persistent timer expires while the server is down all lost timers will be called. 如果服务器关闭或崩溃,则永久计时器将保存并在重新启动服务器时再次变为活动状态。如果在服务器关闭期间持续计时器到期,则将调用所有丢失的计时器。 Non-persistent programmatic timers are created by calling adding persistent=false to annotation: 通过调用为注释添加persistent=false来创建非持久性编程计时器:

@Schedule(second = "0", minute = "*/1", hour = "*",persistent=false)
    public void analisar() throws Exception {
        System.out.println("Starting");
        System.out.println("DONE");
    }

source: http://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html#bnbpa 来源: http : //docs.oracle.com/javaee/6/tutorial/doc/bnboy.html#bnbpa

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

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