java program is not getting called by timer itself -


i have below code here , trying execute whole program on every second using timer, getting called once. called below program on first run command prompt. can guys me on this?

import java.util.timer; import java.util.timertask;  public class task3 {     public static void main(string[] args)  {         final  timer timer = new timer();         timertask task = new timertask() {             @override             public void run() {                 // task run goes here                 system.out.println("hello !!!");                 try {                     dog677_copy.main(new string[0]);                     try {                         thread.sleep(1000);                 //1 min .                     }                     catch(interruptedexception ex) {                         thread.currentthread().interrupt();                     }                     trm.main(new string[0]);                     tstnew.main(new string[0]);                      timer.cancel();                     timer.purge();                  } catch (exception ex) {                     // handle exception,                     // in case throwing runtimeexception ex cause                     throw new illegalstateexception("i didn't expect exception.", ex);                 }             }         };          long delay = 0;         long intevalperiod = 1 * 240000;          // schedules task run in interval          // timer.scheduleatfixedrate(task, delay,intevalperiod);         timer.schedule(task, 0, 1000);          system.out.println("hello !!!");     } // end of main } 

you should remove timer.cancel() run() method. according api documentation of cancel() method:

note calling method within run method of timer task invoked timer absolutely guarantees ongoing task execution last task execution ever performed timer.


Comments