How to stop the task scheduled in java.util.Timer class

前端 未结 5 2027
走了就别回头了
走了就别回头了 2020-11-27 12:44

I am using java.util.Timer class and I am using its schedule method to perform some task, but after executing it for 6 times I have to stop its task.

How

5条回答
  •  悲哀的现实
    2020-11-27 13:16

    Terminate the Timer once after awake at a specific time in milliseconds.

    Timer t = new Timer();
    t.schedule(new TimerTask() {
                @Override
                 public void run() {
                 System.out.println(" Run spcific task at given time.");
                 t.cancel();
                 }
     }, 10000);
    

提交回复
热议问题