java - 将自定义系统日期设置为计划程序

标签 java spring scheduled-tasks quartz

我需要执行具有可自定义系统日期的计划任务,例如,我应该能够将计划程序日期设置为 2019-01-15,在这种情况下,计划程序必须执行该日期计划的所有任务,了解当前日期是 2019-02-12。目前,我只看到了使用 Spring 或 Quartz 的时区解决方案。 谢谢!.

最佳答案

使用TaskScheduler模块:

private TaskScheduler scheduler;

Runnable exampleRunnable = new Runnable(){
    @Override
    public void run() {
        System.out.println("Executing task");
    }
};

@Async
public void executeTaskT() {
    ScheduledExecutorService localExecutor = Executors.newSingleThreadScheduledExecutor();
    scheduler = new ConcurrentTaskScheduler(localExecutor);

    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    Date scheduledDate = dateFormat.parse("12-02-2019", dateFormat);

    scheduler.schedule(exampleRunnable, scheduledDate);
}

executeTaskT(); //call it somewhere after the spring application has been configured

有关更多信息,请参阅: Spring scheduling task - run only once

关于java - 将自定义系统日期设置为计划程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54652565/

相关文章:

java - 如何添加进度条?

java - Spring Boot JPA 配置中没有名为 'transactionManager' 的可用 bean

java - 存储库 Spring-Data-Cassandra 的自定义实现

java - “Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1;”-使用@Scheduled方法调用删除时

python - Luigi 在任务之间传递小数据

c# - "Always running"控制台应用程序

java - mvn package load other Library 作为 Eclipse

java - Eclipse 中的类路径和构建路径中的不同 jar 文件

java - 检查 ArrayList 是否包含某个字符串,同时不区分大小写

selenium - Windows 任务计划程序中模式 "Run whether user is logged on or not"的屏幕分辨率