Gabor Peto
Gabor Peto

Reputation: 642

Start scheduled jobs in play

I have a class like this:

package jobs;

import play.jobs.Every;
import play.jobs.Job;

@Every("5s")
public class ScheduledJobs extends Job{

    @Override
    public void doJob(){
        System.out.println("Job's done");
    }

}

And the config file contains the following:

#Jobs executor
# ~~~~~~
# Size of the Jobs pool
play.jobs.pool=10

# Execution pool
# ~~~~~
# Default to 1 thread in DEV mode or (nb processors + 1) threads in PROD mode.
# Try to keep a low as possible. 1 thread will serialize all requests (very useful for  debugging purpose)
# play.pool=3

My question is how can I get play to start running this job every 5 second? If I create a ScheduledJobs instance and I call doJob it runs once only. Thank you for your help.

EDIT:

The ScheduledJobs is placed in a jobs package in my app directory.

I tried everything however the job does not execute (even if I try @OnApplicationStar or any other annotation. The job is just not starting. if I call new ScheduledJobs().now() I get a null pointer exception at play.jobs.Job.java line 64. (Play 1.2.3). I need to solve this issue very soon. Please help me.

Upvotes: 1

Views: 1872

Answers (1)

grahamrb
grahamrb

Reputation: 2269

You don't need to call anything in code to get the job to work. After you make your first web request to the server (assuming it's in DEV mode) it will then start executing the Job every 5 seconds.

Upvotes: 1

Related Questions