当前位置:网站首页>ScheduledExecutorService定时器

ScheduledExecutorService定时器

2022-07-06 23:09:00 洋啊桑815



import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class TestDamo {
    
    public static void main(String[] args){
        //ScheduledExecutorService 内部为线程池 弥补了Timer的缺陷
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(3);
        pool.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread()+"执行一次");
            }
        },0,2, TimeUnit.SECONDS);
    }
}
ScheduledExecutorService 内部为线程池 弥补了Timer的缺陷
原网站

版权声明
本文为[洋啊桑815]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_66344432/article/details/125632157