Question

I'm using Google Guice, Guice servlet, and Jersey. I'd like to find an easy way to run scheduled jobs in the JVM. I found the following EJB example that creates "a @Singleton EJB with @Schedule method which executes in the background at specified intervals." This is exactly what I'd like to do but wanted to see an easy way to do this w/o adding an EE dependency.

Java mail how to send automatically an email on condition

Was it helpful?

Solution

You might find the Quartz integration for Guice meets your requirements here -

https://github.com/99soft/guartz

Here's an example of the syntax

@javax.inject.Singleton
@org.nnsoft.guice.guartz.Scheduled(jobName = "test", cronExpression = "0/2 * * * * ?")
public class com.acme.MyJobImpl implements org.quartz.Job {

    @javax.inject.Inject
    private MyCustomService service;

    public void execute(JobExecutionContext context) throws JobExecutionException {
        service.customOperation();
    }

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top