Scheduling multiple tasks using timers

How to assign multiple tasks using java.util.Timer . I want to read multiple files using timers. I think I should give each file a different TimerTask , so that one file gets one instance of TimerTask and the other file gets another, but I don't know how to do it. Please help. Thanks in advance. That's what I'm doing:

  Timer timer = new Timer(); // repeat the check every second timer.schedule(fileWatcherTask, new Date(), 1000); 
+6
source share
1 answer

As the javadoc of the Timer class indicates, your tasks should take very little time. In this case, you can forget about the temporary collision. If your tasks take more than 0.1 seconds, run them in a separate thread. I mean using a timer as a trigger, which simply forces the task to run in a separate thread.

you can also use the quartz planner for the link http://www.mkyong.com/java/quartz-scheduler-example/

if you want to use timer class see example in the following image enter image description here

link for more details

+5
source

Source: https://habr.com/ru/post/907285/


All Articles