运行 Java ScheduledExecutorService 在后台
Run Java ScheduledExecutorService in the background
我有一个每两分钟运行一个进程的 jar 文件。它工作得很好,但如果有人关闭终端,进程就会终止。我正在寻找一种将其作为后台进程执行的方法。这是我的主要内容:
public class SMSAlert {
private static ScheduledExecutorService scheduler;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
scheduler = Executors.newSingleThreadScheduledExecutor();
Alert alert = new Alert();
scheduler.scheduleAtFixedRate(alert, 0, 2, TimeUnit.MINUTES);
}
}
我有一个每两分钟运行一个进程的 jar 文件。它工作得很好,但如果有人关闭终端,进程就会终止。我正在寻找一种将其作为后台进程执行的方法。这是我的主要内容:
public class SMSAlert {
private static ScheduledExecutorService scheduler;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
scheduler = Executors.newSingleThreadScheduledExecutor();
Alert alert = new Alert();
scheduler.scheduleAtFixedRate(alert, 0, 2, TimeUnit.MINUTES);
}
}