java - TimerTask() not doing what was supposed to, only printing one time -
public static void main(string[] args) { timer ttt = new timer(); timertask test = new timertask() { @override public void run() { system.out.println("in"); } }; ttt.schedule(test, 1000); } this supposed print "in" every second printing 1 time. tips? thank you
what
you're using one-shot version of schedule. use overloaded version accepts interval period:
ttt.schedule(test, 0, 1000); aside: newer executorservice preferred on java.util.timer. timer has 1 executing thread, long-running task can delay other tasks. executorservice can operate using thread pool. discussed more here
Comments
Post a Comment