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.

有帮助吗?

解决方案

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top