File tree 1 file changed +7
-6
lines changed
leader-followers/src/main/java/com/iluwatar/leaderfollowers
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 {
67
67
/** Start the work, dispatch tasks and stop the thread pool at last. */
68
68
private static void execute (WorkCenter workCenter , TaskSet taskSet ) throws InterruptedException {
69
69
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
+ }
76
77
}
77
78
78
79
/** Add tasks. */
You can’t perform that action at this time.
0 commit comments