Automatic EJB Timer on Glassfish Server not triggering

落爺英雄遲暮 提交于 2019-12-20 01:59:13

问题


So I'm running a Java EAR application on a Glassfish 3.1. I created a stateless session bean with a single annotated timer function in my EJB Module. I don't have the exact code but it looks something like this:

@Stateless
public class SessionTimerBean {

    public SessionTimerBean(){
       System.out.println("Constructor Called");
    }

    @Schedule(second="*/10", minute="*", hour="*")
    public void scheduleTimer(final Timer t) {
       System.out.println("Timer Called");
    }
}

When I launch Glassfish the debug info seems to indicate that it recognizes the EJB timer annotations and the constructor method for the bean does get called upon launch. But the timer method itself never seems to get triggered at any point.

Has anyone else had this issue? Is there some other configuration I'm missing?

Thanks in advance.


回答1:


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>



回答2:


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



回答3:


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>


来源:https://stackoverflow.com/questions/13092567/automatic-ejb-timer-on-glassfish-server-not-triggering

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