.
This commit is contained in:
parent
03bde29792
commit
b4603fa8f9
@ -13,9 +13,12 @@ redtimer是本人纯手工精心编写的一个任务定时调度器,
|
|||||||
|
|
||||||
|
|
||||||
#### 安装使用教程
|
#### 安装使用教程
|
||||||
|
```
|
||||||
|
TimerExecutor timerExecutor = new TimerExecutor(1);
|
||||||
|
timerExecutor.add(new TaskImpl("a1", new ScheduledExpres("0 2 * * *"));//定时每天2点执行
|
||||||
|
timerExecutor.start();
|
||||||
请看测试案例,以及阅读详细源码,所有的代码也就几百行;
|
请看测试案例,以及阅读详细源码,所有的代码也就几百行;
|
||||||
|
```
|
||||||
#### 参与贡献
|
#### 参与贡献
|
||||||
你可以做这些
|
你可以做这些
|
||||||
1. Fork 本项目
|
1. Fork 本项目
|
||||||
|
@ -15,20 +15,11 @@ public class TaskImpl extends AbstractTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
System.out.println("----");
|
ThreadLocal<SimpleDateFormat> local = new ThreadLocal<>();
|
||||||
System.out.println(new SimpleDateFormat("0: yyyy-MM-dd HH:mm:ss").format(theTime()));
|
SimpleDateFormat sdf = local.get();
|
||||||
System.out.println(new SimpleDateFormat("1: yyyy-MM-dd HH:mm:ss").format(nextTime()));
|
if (sdf == null){
|
||||||
System.out.println(new SimpleDateFormat("2: yyyy-MM-dd HH:mm:ss").format(nextTime()));
|
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
System.out.println(new SimpleDateFormat("3: yyyy-MM-dd HH:mm:ss").format(nextTime()));
|
}
|
||||||
System.out.println(new SimpleDateFormat("4: yyyy-MM-dd HH:mm:ss").format(nextTime()));
|
System.out.printf("执行任务:%s now:%s, %n", name, sdf.format(System.currentTimeMillis()));
|
||||||
System.out.println(new SimpleDateFormat("5: yyyy-MM-dd HH:mm:ss").format(nextTime()));
|
|
||||||
System.out.println(new SimpleDateFormat("6: yyyy-MM-dd HH:mm:ss").format(nextTime()));
|
|
||||||
System.out.println(new SimpleDateFormat("7: yyyy-MM-dd HH:mm:ss").format(nextTime()));
|
|
||||||
System.out.println(new SimpleDateFormat("8: yyyy-MM-dd HH:mm:ss").format(nextTime()));
|
|
||||||
System.out.println(new SimpleDateFormat("9: yyyy-MM-dd HH:mm:ss").format(nextTime()));
|
|
||||||
System.out.println(new SimpleDateFormat("10: yyyy-MM-dd HH:mm:ss").format(nextTime()));
|
|
||||||
System.out.println(new SimpleDateFormat("11: yyyy-MM-dd HH:mm:ss").format(nextTime()));
|
|
||||||
System.out.println(new SimpleDateFormat("12: yyyy-MM-dd HH:mm:ss").format(nextTime()));
|
|
||||||
System.out.println(new SimpleDateFormat("13: yyyy-MM-dd HH:mm:ss").format(nextTime()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,19 +21,7 @@ public class TimerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void t2(){
|
public void t2(){
|
||||||
TimerExecutor timerExecutor = new TimerExecutor(1);
|
TimerExecutor timerExecutor = new TimerExecutor(1);
|
||||||
|
timerExecutor.add(new TaskImpl("a1", new ScheduledExpres(LocalDateTime.now(), "1-40/2 * * * *")));//1-40,定时每分钟执行
|
||||||
timerExecutor.add(new TaskImpl("a1", new ScheduledExpres(LocalDateTime.now(), "1-40 * * * *")) {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
ThreadLocal<SimpleDateFormat> local = new ThreadLocal<>();
|
|
||||||
SimpleDateFormat sdf = local.get();
|
|
||||||
if (sdf == null){
|
|
||||||
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
}
|
|
||||||
System.out.printf("执行任务:%s now:%s, %n", name, sdf.format(System.currentTimeMillis()));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
timerExecutor.start();
|
timerExecutor.start();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user