首页>代码>java中任务调度java.util.Timer,ScheduledExecutor,Quartz的机制说明和demo代码实例分享>/testScheduler/src/com/zuidaima/ScheduledExecutorTest.java
package com.zuidaima; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; /** * @author Lvoy * 使用 ScheduledExecutor 进行任务调度 */ public class ScheduledExecutorTest implements Runnable{ private String jobName = ""; public ScheduledExecutorTest(String jobName) { super(); this.jobName = jobName; } @Override public void run() { System.out.println("execute-> " + jobName); } public static void main(String[] args) { ScheduledExecutorService service = Executors.newScheduledThreadPool(10); long initialDelay1 = 1; long period1 = 1; // 从现在开始1秒钟之后,每隔1秒钟执行一次zuidaima1 service.scheduleAtFixedRate(new ScheduledExecutorTest("zuidaima1"), initialDelay1,period1,TimeUnit.SECONDS); long initialDelay2 = 1; long delay2 = 1; // 从现在开始2秒钟之后,每隔2秒钟执行一次zuidaima2 service.scheduleWithFixedDelay(new ScheduledExecutorTest("zuidaima2"), initialDelay2,delay2,TimeUnit.SECONDS); } }
最近下载更多
123456qqwqa LV11
2019年7月16日
kk268137 LV9
2019年3月25日
四季镇 LV9
2018年9月4日
元芳你怎么看 LV15
2018年5月29日
wwwdawn LV14
2018年5月23日
gaoshuangwen LV2
2017年12月20日
wang1991987 LV2
2017年11月23日
xiangge LV1
2017年10月17日
hujialuo LV3
2017年8月28日
18202838208 LV14
2017年8月7日
最近浏览更多
Oxygeni LV4
2023年4月29日
cx330a LV2
2023年4月26日
林间听风 LV10
2022年8月16日
随缘而遇 LV2
2021年6月16日
sangyy LV10
2020年11月5日
trstrs LV1
2020年10月22日
jackychen1012 LV2
2020年9月23日
kenhomeliu LV29
2020年6月19日
912299793 LV21
2020年5月8日
likezhensan LV8
2020年4月25日