Question

Say I have the following code

 Timer t1 = new Timer();
 t1.scheduleAtFixedRate(new TimerTask() {
        @Override
         public void run(){
             //TASK 1
         }
 },0,2000);

 Timer t2 = new Timer();
 t2.scheduleAtFixedRate(new TimerTask() {
        @Override
         public void run(){
             //TASK 2
         }
 },0,180000);

Would Task1 and Task2 run independent of each other or would Task2 hold up the process for 30 minutes?

If the latter happens, would splitting this into two Threads be the only option?

Was it helpful?

Solution

From the Javadoc of Timer:

Corresponding to each Timer object is a single background thread that is used to execute all of the timer's tasks, sequentially.

Each of your Timer instances will execute independently.

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