线程定时调度

具体参见JDK文档:https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Timer.html

package threadStudy;

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

public class TimerTest extends TimerTask {

    @Override
    public void run() {
        System.out.println("虽然是六月 但还是有点冷...");
        
    }
    
    public static void main(String[] args) {
        TimerTest timerTest = new TimerTest();
        Timer timer = new Timer();
        //1s 后开始执行  每隔2s重复执行
        timer.scheduleAtFixedRate(timerTest, 1000, 2000);
    }

}

定时调度框架:Quartz

https://www.w3cschool.cn/quartz_doc/quartz_doc-2put2clm.html

猜你喜欢

转载自www.cnblogs.com/ustc-anmin/p/11013092.html