简体   繁体   English

如何使用Java在一周中的特定日期的特定时间运行任务?

[英]How to run a task on specific days of the week at a certain time in java?

I would like my users to be able to choose which days of the week they want to schedule a certain task to run in Java. 我希望我的用户能够选择他们希望在一周中的哪几天计划要在Java中运行的特定任务。 As I understand, the ScheduledExecutorService is only able to run a single execution, or execute at fixed rates. 据我了解,ScheduledExecutorService只能运行一次执行,或以固定的速率执行。 I am able to run a task every day at a specific time, but haven't figured out how to do that for specific days. 我能够每天在特定时间运行一项任务,但是在特定的日子里我还不知道如何去做。
Is there a way to run my task on specific days of the week (eg mon, wed, fri)? 有什么办法可以在一周的特定日期(例如星期一,星期三,星期五)运行我的任务?

Also, I know that there are 3rd party libraries out there that would do well for what I'm asking, such as Quartz, but I'm wondering if there is a way to do this using only Java APIs. 另外,我知道现在有第三方库可以很好地满足我的要求,例如Quartz,但是我想知道是否有一种方法可以仅使用Java API来实现。

You can use ScheduledExecutorService . 您可以使用ScheduledExecutorService Please refer below link for details. 请参考下面的链接了解详细信息。

https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何安排 crontrigger 在一周中的某些日子运行? - How to schedule crontrigger to run on certain days of the week? java.time - 是否有函数可以在两天之间查找特定日期(星期几或月份的某天)的数量? - java.time - Is there a function to find number of a specific day (day of week, or day of month) between two days? 如何在特定时间内运行任务 - How to run a task for a specific amount of time ScheduledThreadPoolExecutor 如何在特定时间运行任务? - How does ScheduledThreadPoolExecutor run a task at a specific time? 如何重复运行多个任务并在Java中经过一定时间后将其停止 - How to run a number of task repeatedly and stop it after a certain amount of time in java 安排任务在java中每周运行一次 - Schedule task to run once per week in java 计划任务在给定时间每3天运行一次 - Scheduled task to run every 3 days at given time 如何在一周的特定日期和时间创建多个预定通知 - How do I create multiple scheduled notifications each on specific days of the week and time 如何在java中的特定时间和星期几“制造东西”? - How to “make something” in a specific time and day of the week in java? 如何设置任务在一天的特定时间后运行? - How to set task to run after a certain time in the day?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM