简体   繁体   English

使用另一个Java程序调度Java程序

[英]Scheduling a java program using another java program

As part of automation I want to schedule a java program after 12 hours using another java program that is currently running. 作为自动化的一部分,我想在12小时后使用当前正在运行的另一个Java程序来计划一个Java程序。 My client machine is windows. 我的客户端计算机是Windows。 I can't say when my first script will start and once it ends, it has to schedule the second script which should start after 12 hours. 我不能说我的第一个脚本何时开始,一旦结束,它必须安排第二个脚本,该脚本应在12小时后开始。 Any suggestions on how to do it? 有什么建议吗?

I would use java.util.Timer.schedule(TimerTask task, long delay). 我会使用java.util.Timer.schedule(TimerTask任务,长时间延迟)。 The task that you schedule can then invoke the second java program appropriately. 然后,您计划的任务可以适当地调用第二个Java程序。 For example: 例如:

public void scheduleTask() {
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        public void run() {
            try {
                Runtime.getRuntime().exec("java secondprog.class &");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }, 12*1000*60*60);

}

查看Quartz(一个Java调度库)。

You can use the Windows at command to schedule a task to run. 您可以使用Windows at命令来安排任务运行。 This can be done via a system call. 这可以通过系统调用来完成。

This has already been answered here: https://stackoverflow.com/a/3397348/2471910 这已经在这里得到解答: https : //stackoverflow.com/a/3397348/2471910

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM