Skip to content

Commit 90cf4f5

Browse files
authored
Update ScheduleExecutorServiceControl.java
1 parent 6111362 commit 90cf4f5

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎schedule/ScheduleExecutorServiceControl.java‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public ScheduleExecutorServiceControl() {
2828
* 每天定时安排任务进行执行
2929
*/
3030
private void executeAt6PerDay() {
31+
// 循环任务,按照上一次任务的发起时间计算下一次任务的开始时间
3132
scheduExec.scheduleAtFixedRate(() -> {
3233
log.info("execute at 6");
3334
}, getDelay("6:30:00"), testPerTime, TimeUnit.MILLISECONDS);
@@ -49,6 +50,31 @@ private long getDelay(String time){
4950
long initDelay = DateUtil.getTimeMillis(time) - System.currentTimeMillis();
5051
return initDelay > 0 ? initDelay : ONEDAY + initDelay;
5152
}
53+
54+
public void fixedDelay(){
55+
// 循环任务,以上一次任务的结束时间计算下一次任务的开始时间
56+
mScheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
57+
@Override
58+
public void run() {
59+
Log.e("lzp", "scheduleWithFixedDelay:" + System.currentTimeMillis() / 1000);
60+
try {
61+
Thread.sleep(3000);
62+
} catch (InterruptedException e) {
63+
e.printStackTrace();
64+
}
65+
}
66+
}, 1, 1, TimeUnit.SECONDS);
67+
}
68+
69+
public void schedule(){
70+
// 延时任务
71+
mScheduledExecutorService.schedule(threadFactory.newThread(new Runnable() {
72+
@Override
73+
public void run() {
74+
Log.e("lzp", "first task");
75+
}
76+
}), 1, TimeUnit.SECONDS);
77+
}
5278

5379
public void func(){
5480
//定时任务

0 commit comments

Comments
 (0)