当前位置:网站首页>Timer create timer

Timer create timer

2022-07-07 05:14:00 Yang Asang 815


import java.util.Timer;
import java.util.TimerTask;

public class TestDamo {
    
    public static void main(String[] args) {
        Timer timer=new Timer();// The timer itself is a thread 
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread()+" Do it once ");
            }
        },3000,2000);
        /*
        * Timer A single thread , Process multiple tasks and execute them in sequence , There is a difference between the delay and the time of setting the timer 
        *  Maybe because of one of the exceptions Timer Thread death , Thus affecting subsequent tasks ,
        * */
    }
}

 Timer A single thread , Process multiple tasks and execute them in sequence , There is a difference between the delay and the time of setting the timer
        * Maybe because of one of the exceptions Timer Thread death , Thus affecting subsequent tasks ,

原网站

版权声明
本文为[Yang Asang 815]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207062309112193.html