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.

Was it helpful?

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top