当前位置:网站首页>任务调度线程池-应用定时任务
任务调度线程池-应用定时任务
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);
边栏推荐
- 4.1 配置Mysql与注册登录模块
- 数字孪生北京故宫,元宇宙推进旅游业进程
- KDD2022 | 自监督超图Transformer推荐系统
- 图文详述Eureka的缓存机制/三级缓存
- 解除360对默认浏览器的检测与修改
- Failed to re-init queues : Illegal queue capacity setting (abs-capacity=0.6) > (abs-maximum-capacity
- 【Untitled】
- Creo5.0 rough hexagon is how to draw
- 【节能学院】推进农业水价综合改革的意见解读
- 57: Chapter 5: Develop admin management services: 10: Develop [get files from MongoDB's GridFS, interface]; (from GridFS, get the SOP of files) (Do not use MongoDB's service, you can exclude its autom
猜你喜欢
随机推荐
Redis 做签到统计
自定义指令,获取焦点
The Internet giant development process
【节能学院】数据机房中智能小母线与列头柜方案的对比分析
To promote energy conservation institute 】 【 the opinions of the agricultural water price reform
win10,在proe/creo中鼠标中键不能放大缩小
nacos安装与配置
正则表达式
【七夕特别篇】七夕已至,让爱闪耀
kingbaseV8R3和postgreSQL哪个版本最接近?
An implementation of an ordered doubly linked list.
KDD2022 | 自监督超图Transformer推荐系统
模板特例化和常用用法
nacos installation and configuration
How PROE/Croe edits a completed sketch and brings it back to sketching state
作为程序员你应该会的软件
【kali-信息收集】(1.6)服务的指纹识别:Nmap、Amap
SIPp 安装及使用
漏刻有时文档系统之XE培训系统二次开发配置手册
Zheng Xiangling, Chairman of Tide Pharmaceuticals, won the "2022 Outstanding Influential Entrepreneur Award" Tide Pharmaceuticals won the "Corporate Social Responsibility Model Award"
![[Personal work] Wireless network image transmission module](/img/64/c0cec74692df7ca05c1a5317e21c9d.png)







