简体   繁体   中英

EJB Schedule automatic start on weblogic

I currently have an EJB that has an @ schedule that runs every 5 minutes, but I only run after the ejb initialized.

the question is whether you can make the timer starts running after deployment and do not wait until there is an invocation to the EJB for starting.

Here is my code:

@Remote(ServiceRemote.class)
@Stateless(mappedName = "ejb/ServiceEJBSL")
public class ServiceBean implements ServiceRemote {
@Schedule(second="*", minute="*/5", hour="*", dayOfWeek="0-6")
public void autmaticTimer() throws Exception, RemoteException{
System.out.println("do something");
}
}

I did this in glasfish server but it seems doesnt work the same way.

Thanks in advance.

You'll need GlassFish v3.+ because this feature was added in EJB 3.1

Automatic timers are created by the EJB container when an enterprise bean that contains methods annotated with the @Schedule or @Schedules annotations is deployed.

@Schedule(minute="*/5", hour="*")
public void automaticTimer() throws Exception, RemoteException{
   System.out.println("do something");
}

Addition

Try to add

@Schedule(minute="*/5", hour="*", persistent=false)

Because persistent timers are not re-created if already existing when keepstate is set to true .

See

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM