Skip to content

Commit

Permalink
#2883: shutdown ExecutorService in a finally clause
Browse files Browse the repository at this point in the history
  • Loading branch information
c71n93 committed Feb 21, 2024
1 parent 77c3757 commit 7dddfc7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -327,8 +328,10 @@ protected final ForeignTojos scopedTojos() {
* @throws TimeoutException If timeout limit reached
*/
private void execWithTimeout() throws ExecutionException, TimeoutException {
ExecutorService service = null;
try {
Executors.newSingleThreadExecutor().submit(
service = Executors.newSingleThreadExecutor();
service.submit(
() -> {
this.exec();
return new Object();
Expand All @@ -343,6 +346,10 @@ private void execWithTimeout() throws ExecutionException, TimeoutException {
),
ex
);
} finally {
if (service != null) {
service.shutdown();
}
}
}

Expand Down

0 comments on commit 7dddfc7

Please sign in to comment.