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

三世轮回 提交于 2019-12-06 01:44:28

问题


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.

Session 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. message, but the method sayHello() is never called.

According to the tutorial the @Schedule(second="*") means that it should execute every 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.

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.


回答1:


Use @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.



来源:https://stackoverflow.com/questions/24194638/java-ee-7-automatic-timer-ejb-timer-not-working-for-wildfly-8-1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!