Use CountDownLatch if you want to start both threads simultaneously.
Since you have the above code, t1 gets the right to run (Runnable) to t2. So, before the Java Scheduler, you can choose whether to mix t1 and t2 or first complete t1 and then t2. But if you want t1 and t2 to wait for the cue to start, CountDownLatch will help you with this.
public class timercheck extends TimerTask{ private final CountDownLatch countDownLatch = new CountDownLatch(1);
For more information on CountDownLatch, Semaphore, and CyclicBarrier, read this post.
source share