2
我有三個獨立任務要在每1分鐘執行一次。 在這裏我已經開發了兩個選項。如何使用ExecutorService安排多個任務
選項1
ScheduledExecutorService service1 = Executors.newScheduledThreadPool(1);
ScheduledExecutorService service2 = Executors.newScheduledThreadPool(1);
ScheduledExecutorService service2 = Executors.newScheduledThreadPool(1);
service1.scheduleAtFixedRate(new task1(), 0, 60, TimeUnit.SECONDS);
service2.scheduleAtFixedRate(new task2(), 0, 60, TimeUnit.SECONDS);
service3.scheduleAtFixedRate(new task3(), 0, 60, TimeUnit.SECONDS);
1選項
ScheduledExecutorService service = Executors.newScheduledThreadPool(3);
service.scheduleAtFixedRate(new task1(), 0, 60, TimeUnit.SECONDS);
service.scheduleAtFixedRate(new task2(), 0, 60, TimeUnit.SECONDS);
service.scheduleAtFixedRate(new task3(), 0, 60, TimeUnit.SECONDS);
我的問題是其選擇是首選? Option1是否消耗更多的系統資源?