当前位置:网站首页>任务调度线程池-应用定时任务
任务调度线程池-应用定时任务
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);
边栏推荐
- 瀚高数据导入
- 9月备考PMP,应该从哪里备考?
- 【Dart】dart之mixin探究
- 【ES】ES2021 我学不动了,这次只学 3 个。
- Compose实战-实现一个带下拉加载更多功能的LazyColumn
- 【多任务优化】DWA、DTP、Gradnorm(CVPR 2019、ECCV 2018、 ICML 2018)
- "Torch" tensor multiplication: matmul, einsum
- kingbaseV8R3和postgreSQL哪个版本最接近?
- Win10, the middle mouse button cannot zoom in and out in proe/creo
- The configuration manual for the secondary development of the XE training system of the missing moment document system
猜你喜欢
随机推荐
因斯布鲁克大学团队量子计算硬件突破了二进制
4.1 配置Mysql与注册登录模块
密码学的基础:X.690和对应的BER CER DER编码
nacos installation and configuration
[Energy Conservation Institute] Application of Intelligent Control Device in High Voltage Switchgear
不同的操作加不同的锁详解
通配符 SSL/TLS 证书
图文详述Eureka的缓存机制/三级缓存
[Multi-task optimization] DWA, DTP, Gradnorm (CVPR 2019, ECCV 2018, ICML 2018)
To promote energy conservation institute 】 【 the opinions of the agricultural water price reform
第60章 ApplicationPart自动集成整体性和独立性插件项
【Dart】dart之mixin探究
Win10, the middle mouse button cannot zoom in and out in proe/creo
myid file is missing
【Untitled】
启明云端分享|盘点ESP8684开发板有哪些功能
Greenplum Database Source Code Analysis - Analysis of Standby Master Operation Tools
【七夕特别篇】七夕已至,让爱闪耀
Hangao data import
Software you should know as a programmer