|
2 | 2 |
|
3 | 3 | import com.dumptruckman.minecraft.util.Logging; |
4 | 4 | import org.jvnet.hk2.annotations.Service; |
5 | | -import org.mvplugins.multiverse.external.jakarta.inject.Inject; |
| 5 | +import org.mvplugins.multiverse.external.jakarta.annotation.PreDestroy; |
6 | 6 | import org.mvplugins.multiverse.external.vavr.control.Try; |
7 | 7 |
|
8 | 8 | import java.io.File; |
9 | 9 | import java.util.Map; |
10 | 10 | import java.util.concurrent.CompletableFuture; |
11 | 11 | import java.util.concurrent.ConcurrentHashMap; |
12 | 12 | import java.util.concurrent.CountDownLatch; |
13 | | -import java.util.concurrent.ExecutionException; |
14 | 13 | import java.util.concurrent.ExecutorService; |
15 | 14 | import java.util.concurrent.Executors; |
16 | 15 | import java.util.concurrent.TimeUnit; |
17 | | -import java.util.concurrent.TimeoutException; |
18 | 16 | import java.util.function.Supplier; |
19 | 17 |
|
20 | 18 | @Service |
@@ -105,4 +103,20 @@ private void waitForLock(File file, CountDownLatch toWaitLatch) { |
105 | 103 | ExecutorService getExecutor() { |
106 | 104 | return fileIOExecutorService; |
107 | 105 | } |
| 106 | + |
| 107 | + @PreDestroy |
| 108 | + private void completeRemainingTaskAndShutdown() { |
| 109 | + fileIOExecutorService.shutdown(); |
| 110 | + try { |
| 111 | + if (!fileIOExecutorService.awaitTermination(60, TimeUnit.SECONDS)) { |
| 112 | + fileIOExecutorService.shutdownNow(); |
| 113 | + if (!fileIOExecutorService.awaitTermination(60, TimeUnit.SECONDS)) { |
| 114 | + Logging.severe("File IO executor did not terminate"); |
| 115 | + } |
| 116 | + } |
| 117 | + } catch (InterruptedException ie) { |
| 118 | + fileIOExecutorService.shutdownNow(); |
| 119 | + Thread.currentThread().interrupt(); |
| 120 | + } |
| 121 | + } |
108 | 122 | } |
0 commit comments