Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Blog scheduler
class JobRunnable implements Runnable
{
private final Job job;
public JobRunnable(Job job)
{
this.job = job;
}
@Override
void run()
{
while(true)
{
Thread.sleep(job.getNextExecutionTime() - currentTime());
job.execute();
job.setNextExecutionTime(currentTime() + job.getExecutionInterval());
}
}
}
public CrontabRunnable implements Runnable
{
private final ExecutorService executorService = Executors.newFixedThreadPool(4);
@Override
void run()
{
while(true)
{
newJob = getNewJobFromCrontabFile() // blocking call
executorService.execute(new JobRunnable(newJob));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment