清除EJB中@Schedule的缓存 [英] Clear cache of @Schedule in EJB

查看:87
本文介绍了清除EJB中@Schedule的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单例类,可以在一定时间间隔内执行任务.当应用程序开始正常运行时,任务将在适当的时间段内运行,并且该间隔足够长,以至于任何任务都不会重叠.

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.

课程在下面显示:

@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");
    }
 }

使用的Web容器是Wildfly 10.

The web container used is Wildfly 10.

问题是,例如,当应用程序在停机一小时后启动时,该任务将按顺序执行,在这种情况下,将全部执行60次调用,此后将自动恢复1分钟的时间. 我是否需要清除任何缓存以避免吮吸行为?

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. Do I have to clear any cache to avoid suck behavior?

推荐答案

默认情况下,计时器是持久性的.如果服务器关闭或崩溃,则永久性计时器将保存并在重新启动服务器时再次变为活动状态.如果在服务器停机时永久性计时器到期,则将调用所有丢失的计时器. 通过调用在注释中添加persistent=false来创建非持久性编程计时器:

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:

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

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

这篇关于清除EJB中@Schedule的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆