Javaでデーモンサービスジョブを作成しようとしています。このサービスは毎分実行されます。Java ExecutorService無限ループジョブ
私はExecutorServiceを使用してこれを実装することはできませんが、これが正しい方法であるかどうかわかりません。以下は私のコードスニペットです:for(;;)
、無break文:
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