Automatic EJB Timer on Glassfish Server not triggering
Asked Answered
E

3

3

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.

Equisetum answered 26/10, 2012 at 18:41 Comment(4)
Does it make a diff u remove the parameter from the method?Plash
i would also check that imports are correct javax.ejb.Timer etc..Plash
Any luck with that? Same problem here, no method paramsBroomcorn
Used to have similar issue see: #13292973Presa
P
4

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>
Plash answered 27/10, 2012 at 18:13 Comment(1)
It's worth noting that depending on the application, it may be better setting persistent=false so as to keep keep-state=true. In that case, web sessions, Stateful Session EJB instances and persistently created EJB timers can be retained between re-deployments. docs.oracle.com/cd/E18930_01/html/821-2417/gkhtr.htmlBroomcorn
B
4

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
Blanton answered 7/11, 2012 at 14:23 Comment(0)
A
2

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>
Androclinium answered 18/12, 2015 at 14:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.