|
31 | 31 | import java.util.Collection; |
32 | 32 | import java.util.List; |
33 | 33 | import java.util.Objects; |
34 | | -import java.util.concurrent.*; |
| 34 | +import java.util.concurrent.ConcurrentHashMap; |
| 35 | +import java.util.concurrent.ConcurrentMap; |
| 36 | +import java.util.concurrent.ExecutorService; |
| 37 | +import java.util.concurrent.Executors; |
35 | 38 | import java.util.stream.Collectors; |
36 | 39 | import javax.annotation.Nonnull; |
37 | 40 | import javax.annotation.concurrent.ThreadSafe; |
@@ -102,10 +105,8 @@ public ExecutorService getExecutorService(@NonNull Object sequenceKey) { |
102 | 105 | */ |
103 | 106 | @Override |
104 | 107 | public void close() { |
105 | | - Collection<ShutdownDisabledExecutorService> shutdownDisabledExecutorServices = sequentialExecutors.values(); |
106 | | - shutdownDisabledExecutorServices.forEach(ShutdownDisabledExecutorService::closeDelegate); |
107 | | - awaitForever().until(() -> shutdownDisabledExecutorServices.stream() |
108 | | - .allMatch(ShutdownDisabledExecutorService::isTerminated)); |
| 108 | + sequentialExecutors.values().forEach(ShutdownDisabledExecutorService::shutdownDelegate); |
| 109 | + awaitForever().until(this::isTerminated); |
109 | 110 | } |
110 | 111 |
|
111 | 112 | private int bucketOf(Object sequenceKey) { |
@@ -169,27 +170,6 @@ public void shutdown() { |
169 | 170 | throw new UnsupportedOperationException(SHUTDOWN_UNSUPPORTED_MESSAGE); |
170 | 171 | } |
171 | 172 |
|
172 | | - void closeDelegate() { |
173 | | - boolean terminated = isTerminated(); |
174 | | - if (!terminated) { |
175 | | - shutdownDelegate(); |
176 | | - boolean interrupted = false; |
177 | | - while (!terminated) { |
178 | | - try { |
179 | | - terminated = awaitTermination(1L, TimeUnit.DAYS); |
180 | | - } catch (InterruptedException e) { |
181 | | - if (!interrupted) { |
182 | | - shutdownDelegateNow(); |
183 | | - interrupted = true; |
184 | | - } |
185 | | - } |
186 | | - } |
187 | | - if (interrupted) { |
188 | | - Thread.currentThread().interrupt(); |
189 | | - } |
190 | | - } |
191 | | - } |
192 | | - |
193 | 173 | void shutdownDelegate() { |
194 | 174 | this.delegate.shutdown(); |
195 | 175 | } |
|
0 commit comments