JDK
JDK代码实践:https://blog.csdn.net/haoranhaoshi/article/details/102897849
JavaFX代码实践:https://blog.csdn.net/haoranhaoshi/article/details/105120277
Spring
代码实践(源码见:ScheduledAnnotationBeanPostProcessor):
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import java.util.concurrent.Executors;
@Configuration
public class ScheduleConfig implements SchedulingConfigurer {
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
scheduledTaskRegistrar.setScheduler(Executors.newScheduledThreadPool(100));
}
}
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* @author zhanghao
*/
@SpringBootApplication
@EnableScheduling
public class ScheduledApplication {
public static void main(String[] args) {
// https://blog.csdn.net/weixin_40318210/article/details/78149692
SpringApplication.run(ScheduledApplication.class, args);
}
}
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
/**
* @author zhanghao
*/
@Component
public class TestJob {
@Scheduled(initialDelay = 1000, fixedRate = 1000 * 10) //1秒后执行,每10秒执行一次
// ScheduledAnnotationBeanPostProcessor
public void Task1() throws InterruptedException {
System.out.println("task1 任务开始, 线程执行ID:" + Thread.currentThread().getId() + "线程名称:" + Thread.currentThread().getName());
TimeUnit.SECONDS.sleep(10);
System.out.println("task1 任务结束, 线程执行ID:" + Thread.currentThread().getId() + "线程名称:" + Thread.currentThread().getName());
}
@Scheduled(initialDelay = 1000, fixedRate = 1000 * 5) //每5秒执行一次
public void Task2() throws InterruptedException {
System.out.println("task2 任务开始, 线程执行ID:" + Thread.currentThread().getId() + "线程名称:" + Thread.currentThread().getName());
TimeUnit.SECONDS.sleep(10);
System.out.println("task2 任务结束, 线程执行ID:" + Thread.currentThread().getId() + "线程名称:" + Thread.currentThread().getName());
}
}
Quartz
quartz代码实践(源码见:QuartzSchedulerThread):https://blog.csdn.net/haoranhaoshi/article/details/102897849
XXL-Job
Elastic-Job
SchedulerX
DTS:https://blog.csdn.net/yunqiinsight/article/details/90711911
工作流设置:https://help.aliyun.com/document_detail/148205.html?spm=a2c4g.11186623.6.591.1f9547d6JjQaIQ