Last active
May 30, 2020 15:33
-
-
Save Anmol-Singh-Jaggi/c9e942358b7f4453839c07762aabd079 to your computer and use it in GitHub Desktop.
blog scheduler approach 2
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
void goToSleep(job, jobQueue){ | |
jobQueue.push(job); | |
sleep(job.nextExecutionTime() - getCurrentTime()); | |
} | |
void executeJob(job, jobQueue){ | |
threadpool.submit(job); // async call | |
job = job.copy(); | |
job.setNextExecutionTime(getCurrentTime() + job.getExecutionInterval()); | |
jobQueue.add(job); | |
} | |
@Override | |
void run(){ | |
while(true) | |
{ | |
job = jobQueue.pop() | |
if(job.nextExecutionTime() > getCurrentTime()){ | |
// Nothing to do | |
goToSleep(job, jobQueue) | |
} | |
else{ | |
executeJob(job, jobQueue) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment