Question

I use

timer.schedule(new DoReassignement(), delay, controlInterval);

And want to add

timer.scheduleAtFixedRate(fetchMail, getTomorrowMorning4am(), fONCE_PER_DAY);

Should I use different Timer object for new task or I shouldnt ? Thanks in advance.

Edit: my tasks sometimes could be(and should be) executed at the same time, but I dont want for each of them to delay or wait.

Était-ce utile?

La solution

You can schedule multiple tasks on the timer. Each task is run by the same timer thread though, so the tasks should be short. If they're not, they can back up the timer.

Autres conseils

You can reuse a timer for multiple tasks. It'll only throw an IllegalStateException if you attempt to schedule the same task 2x

See the scheduleAtFixedRate documentation

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top