Automatic EJB Timer on Glassfish Server not triggering

天涯浪子 提交于 2019-12-01 20:19:37

Below Timer code works in glassfish 3.1.2

import javax.ejb.Schedule;
import javax.ejb.Stateless;
import javax.ejb.Timer;

@Stateless
public class LabbBean {

    @Schedule(second="*/5", minute="*",hour="*", persistent=false)
    public void method123(final Timer timer) {
        System.out.println("Timer1234");
    }
}

but stoped working when I removed the

persistent=false 

So in the server-log i found:

INFO: keepstate is true and will not create new auto timers during deployment.

So i changed 'keep-state' to false. I'm no expert what it also does, but changing it to false made the timer work without persistent=false

I changed it in below files

glassfish-ejb.xml:

<glassfish-ejb-jar>
    <enterprise-beans>
    ...
    </enterprise-beans>
    <keep-state>false</keep-state>
</glassfish-ejb-jar>

glassfish-application.xml

<glassfish-application>
    <keep-state>false</keep-state>
</glassfish-application>

According to the spec, Timers are persistent by convention:

The timer service is intended for the modelling of long-lived business processes. Timers survive container crashes, server shutdown, and the activation/passivation and load/store cycles of the enterprise beans that are registered with them. These persistent guarantees can optionally be disabled on a per-timer basis.

Aksel demonstrated how persistent guarantees can be disabled. The glassfish server uses its default database for persisting its timers (take a look here). I could imagine that it was not up and running and because of that the timers did not work. Use the following command to start it:

asadmin start-database

I run into the same issue when I was following a tutorial. I was using Glassfish 4.1 (JavaEE 7 implementation). I was getting the same error

Infos: There are no EJB Timers owned by this server

I just created a Dynamic Web Module. Not an EAR project with an EJB module. Following the above answers I first changed my @Schedule() annotation by inserting the persistent=false attribut like so

@Schedule(second="/10", minute="", hour="8-23", dayOfWeek="Mon-Fri", dayOfMonth="", month="", year="*", info="MyTimer", persistent=false)

Then I went to my glasshish-web.xml deployment descriptor and I place the following configuration <keep-state>false</keep-state> in the section like so:

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