Blog scheduler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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