JBoss AS 7.1 - running schedule using @Schedule annotation
Asked Answered
N

3

6

Anyone know how to make @Schedule annotation work on JBoss AS 7?

I know that on Glassfish-3.1.2 it works out-of-box.

I try this:

@ManagedBean
@Stateless(name="ImportStatementSchedule")
public class ImportStatementSchedule implements Serializable{
private Logger _log = Logger.getLogger(this.getClass());

    @Schedule(minute="*")
    public void executeImport(){
        _log.info("Scheduled task started");
    }

}

I expect receive log message every minute, but nothing ;)

I checked these forum threads, but nothing helps :

https://community.jboss.org/message/623574

https://community.jboss.org/message/621893

https://community.jboss.org/message/637567

A have JBoss AS 7.1.1-Final

Maybe I forgot something, please can anyone point me to right way?

UPDATE:

I know that JBoss register my EJB to JNDI :

11:07:05,548 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-6) JNDI bindings for session bean named ImportStatementSchedule in deployment unit deployment "finadv.war" are as follows:

    java:global/finadv/ImportStatementSchedule!finadv.bean.ImportStatementSchedule
    java:app/finadv/ImportStatementSchedule!finadv.bean.ImportStatementSchedule
    java:module/ImportStatementSchedule!finadv.bean.ImportStatementSchedule
    java:global/finadv/ImportStatementSchedule
    java:app/finadv/ImportStatementSchedule
    java:module/ImportStatementSchedule

UPDATE2

It has been solved as mentioned in comments

Nutriment answered 1/5, 2012 at 9:2 Comment(1)
See this thread, particularly the "hour" parameter: #10247106Divaricate
M
6

Timer service is EJB service. ImportStatementSchedule should be a @Stateless or @Singleton session bean. From the EJB 3.1 Specification, Section 18.2:

For automatically created timers, the timeout method may be a method that is annotated with the Schedule annotation. Timers can be created for stateless session beans, singleton session beans, mes- sage-driven beans, and 2.1 entity beans. Timers cannot be created for stateful session beans.

The INFO log statement is misleading. JBoss does not register an EJB. It just uses the same naming scheme as defined by the @ManagedBean annotation (Javadoc):

[..] Managed Bean names must be unique within a Java EE module. For each named Managed Bean, Java EE containers must make available the following entries in JNDI, using the same naming scheme used for EJB components. In the application namespace:

java:app/<module-name>/<bean-name>

In the module namespace of the module containing the Managed Bean:

java:module/<bean-name>

Microlith answered 1/5, 2012 at 11:4 Comment(3)
+1 for good reference, but I tried before both Stateless or Singleton annotation, now I know that problem was as @Nick Wilson mentioned in hour parameter.Nutriment
thx, @rkosegi. does that mean that you can use @Schedule without using @Stateless or @Singleton?Microlith
No, it means that I was not able to make it work until I set hour parameter to "*". Currently I'm using Stateless annotation and it works.Nutriment
P
4

I can add, that if you write

@Schedule(minute="*")

it will only fire at midnight. Because the hour parameter is default: 0.

Try: @Schedule(minute = "/1", hour = "") or something like this. In my case it helped.

Publicist answered 24/7, 2012 at 14:47 Comment(0)
C
0

You must specify hours, try:

@Schedule(hour="\*", minute="\*")
Consciousness answered 18/2, 2016 at 17:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.