简体   繁体   English

Java EE 7自动计时器(EJB计时器)不适用于WildFly 8.1.0

[英]Java EE 7 Automatic Timer (EJB Timer) not working for WildFly 8.1.0

I am following the Using the Timer Service tutorial to build a simple scheduled execution. 我正在按照使用定时器服务教程来构建一个简单的计划执行。 Trying the automatic approach and using WildFly 8.1.0 Final for it. 尝试自动方法并使用WildFly 8.1.0 Final

Session Bean 会话Bean

@Singleton
@Startup
public class HelloJob {

    private static final Logger logger = Logger.getLogger(HelloJob.class);

    public HelloJob() {
        logger.error(">>> Hello Job Created.");
    }

    @Schedule(second="*")
    public void sayHello() {
        logger.error(">>> Server Hello!");
    }

}

On deploy the class is properly instantiated printing the >>> Hello Job Created. 在部署时,正确实例化类,打印>>> Hello Job Created. message, but the method sayHello() is never called. 消息,但方法sayHello()永远不会被调用。

According to the tutorial the @Schedule(second="*") means that it should execute every second. 根据教程,@ @Schedule(second="*")表示它应该每秒执行一次。

Setting an attribute to an asterisk symbol (*) represents all allowable values for the attribute. 将属性设置为星号(*)表示属性的所有允许值。

Also only stateful session beans are not allowed for timers, and I am using a singleton, which is also used in the example. 同样只有有状态会话bean不允许用于计时器,我使用的是单例,也在示例中使用。

The timer service of the enterprise bean container enables you to schedule timed notifications for all types of enterprise beans except for stateful session beans. 企业bean容器的计时器服务使您可以为除有状态会话bean之外的所有类型的企业bean计划定时通知。

Use @Schedule(second="*", minute="*", hour="*") . 使用@Schedule(second="*", minute="*", hour="*")

the default values for hour and minute are "0" which can be quite irritating and effectively forces you to set these. 小时和分钟的默认值为“0”,这可能会非常刺激,并且会强制您设置这些值。

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

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