我正尝试在java中编写守护程序服务作业。这项服务将每分钟运行一次。Java ExecutorService无限循环作业
但我不能通过使用ExecutorService实现这一点,我不知道这是否是正确的方式。下面是我的代码片段:
public void startService() {
try {
ExecutorService service = Executors.newFixedThreadPool(3);
for (;;) {
service.submit(new Service1()); // this will send some set of emails
service.submit(new Service2()); // this will send some set of emails
service.submit(new Service3()); // this will send some set of sms
}
service.shutdown(); // It says Unreachable code so when should i shutdown the service
service.awaitTermination(1, TimeUnit.MINUTES);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
是的,它没有结束工作。它会每分钟运行一次。你能说说怎么做到这一点。 – DEADEND