Вопрос

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