File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed
leader-followers/src/main/java/com/iluwatar/leaderfollowers Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -67,12 +67,13 @@ public static void main(String[] args) throws InterruptedException {
6767 /** Start the work, dispatch tasks and stop the thread pool at last. */
6868 private static void execute (WorkCenter workCenter , TaskSet taskSet ) throws InterruptedException {
6969 var workers = workCenter .getWorkers ();
70- var exec = Executors .newFixedThreadPool (workers .size ());
71- workers .forEach (exec ::submit );
72- Thread .sleep (1000 );
73- addTasks (taskSet );
74- exec .awaitTermination (2 , TimeUnit .SECONDS );
75- exec .shutdownNow ();
70+ try (var exec = Executors .newFixedThreadPool (workers .size ())) {
71+ workers .forEach (exec ::submit );
72+ Thread .sleep (1000 );
73+ addTasks (taskSet );
74+ exec .awaitTermination (2 , TimeUnit .SECONDS );
75+ exec .shutdownNow ();
76+ }
7677 }
7778
7879 /** Add tasks. */
You can’t perform that action at this time.
0 commit comments