I have a class that runs for every 10 secs, but when I execute it more than once, multiple timers are started. If one timer is already running, I want the other timer calls to be ignored. I want only one timer to be running at a given point of time. Please help.
My code:
import java.util.Timer;
import java.util.TimerTask;
public class Test1 extends TimerTask{
@Override
public void run() {
System.out.println("In run method");
}
public static void main(String args[]) {
System.out.println("In main method");
Timer timer= new Timer();
timer.schedule(new Test1(), 10000,10000);
}
}