【发布时间】:2017-02-21 12:20:09
【问题描述】:
我正在尝试用 java 编写守护程序服务作业。该服务将每分钟运行一次。
但我无法通过使用 ExecutorService 来实现这一点,我不知道这是否是正确的方法。下面是我的代码sn-p:
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();
}
}
【问题讨论】:
标签: java multithreading executorservice