当前位置:网站首页>任务调度线程池-应用定时任务
任务调度线程池-应用定时任务
2022-08-01 20:22:00 【Q z1997】
任务调度线程池-应用定时任务
示例每周四18:00:00 执行
// 获得当前时间
LocalDateTime now = LocalDateTime.now();
// 获取本周四 18:00:00.000
LocalDateTime thursday =
now.with(DayOfWeek.THURSDAY).withHour(18).withMinute(0).withSecond(0).withNano(0);
// 如果当前时间已经超过 本周四 18:00:00.000, 那么找下周四 18:00:00.000
if (now.compareTo(thursday) >= 0) {
thursday = thursday.plusWeeks(1);
}
// 计算时间差,即延时执行时间
long initialDelay = Duration.between(now, thursday).toMillis();
// 计算间隔时间,即 1 周的毫秒值
long oneWeek = 7 * 24 * 3600 * 1000;
ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
System.out.println("开始时间:" + new Date());
executor.scheduleAtFixedRate(() -> {
System.out.println("执行时间:" + new Date());
}, initialDelay, oneWeek, TimeUnit.MILLISECONDS);
边栏推荐
- 【Untitled】
- Use WeChat official account to send information to designated WeChat users
- 我的驾照考试笔记(1)
- 环境变量,进程地址空间
- [Multi-task optimization] DWA, DTP, Gradnorm (CVPR 2019, ECCV 2018, ICML 2018)
- 【多任务优化】DWA、DTP、Gradnorm(CVPR 2019、ECCV 2018、 ICML 2018)
- 不同的操作加不同的锁详解
- LabVIEW 使用VISA Close真的关闭COM口了吗
- 【节能学院】智能操控装置在高压开关柜的应用
- Interpretation of the meaning of each dimension of two-dimensional, three-dimensional, and four-dimensional matrices
猜你喜欢

第59章 ApplicationPart内置依赖注入中间件

实用新型专利和发明专利的区别?秒懂!

研究生新同学,牛人看英文文献的经验,值得你收藏

智能硬件开发怎么做?机智云全套自助式开发工具助力高效开发

小数据如何学习?吉大最新《小数据学习》综述,26页pdf涵盖269页文献阐述小数据学习理论、方法与应用

regular expression

18. Distributed configuration center nacos

KDD2022 | Self-Supervised Hypergraph Transformer Recommendation System

Intranet penetration lanproxy deployment

LTE time domain and frequency domain resources
随机推荐
【Dart】dart之mixin探究
漏刻有时文档系统之XE培训系统二次开发配置手册
18. Distributed configuration center nacos
【torch】张量乘法:matmul,einsum
Redis does check-in statistics
终于有人把AB实验讲明白了
18、分布式配置中心nacos
【个人作品】无线网络图传模块
实用新型专利和发明专利的区别?秒懂!
虚拟机的IP地址自动变为127.0.0.1
9月备考PMP,应该从哪里备考?
Does LabVIEW really close the COM port using VISA Close?
研究生新同学,牛人看英文文献的经验,值得你收藏
An implementation of an ordered doubly linked list.
The graphic details Eureka's caching mechanism/level 3 cache
Intranet penetration lanproxy deployment
Creo5.0 rough hexagon is how to draw
Custom command to get focus
deploy zabbix
【Social Media Marketing】How to know if your WhatsApp is blocked?