How to write an efficient scheduler in Java - Part 1