I’m tryng to write a simple Java program that runs some code every hour when the minute hand is at 20. The issue is that that the way I’m doing it is incredibly CPU intensive. I’m familiar with Quartz but I’m looking for a much simpler solution, any ideas?
boolean run = true;
while(run){
Calendar calendar = new GregorianCalendar();
int minute = calendar.get(Calendar.MINUTE);
if(minute == 20){
//Do some Stuff
}
}
A simple solution is to use the Executors framework:
And use some logic to find out
secondsToFirstOccurence. This will probably involve aCalendarinstance, but would be much more convenient with JodaTime.