Поправил закрытие пулов потоков Executors.

This commit is contained in:
AKurakin 2022-12-30 17:16:01 +03:00
parent 19702fb5e0
commit ba8dead115
4 changed files with 14 additions and 8 deletions

View file

@ -47,6 +47,7 @@ public class ClearingService implements DisposableBean {
@Override
public void destroy() throws Exception {
log.debug("Shutdown {}", getClass().getSimpleName());
executor.shutdown();
}
}

View file

@ -23,8 +23,6 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Function;
import java.util.stream.Collectors;

View file

@ -83,16 +83,20 @@ public abstract class AbstractHazelcastLifecycleSupport implements InitializingB
return maxKey;
});
}
long maxKey = 0L;
int threadCount = Runtime.getRuntime().availableProcessors();// todo config * Config.get().getRoot().getSettings().getInitHazelcastThreadMultiplier();
log.info("Initializing threads count = {}", threadCount);
ExecutorService executor = Executors.newWorkStealingPool(threadCount);
List<Future<Long>> results = executor.invokeAll(tasks);
long maxKey = 0L;
for (Future<Long> result : results) {
Long maxKeyResult = result.get();
if (maxKeyResult != null) {
maxKey = Math.max(maxKey, maxKeyResult);
try {
List<Future<Long>> results = executor.invokeAll(tasks);
for (Future<Long> result : results) {
Long maxKeyResult = result.get();
if (maxKeyResult != null) {
maxKey = Math.max(maxKey, maxKeyResult);
}
}
} finally {
executor.shutdown();
}
IdGenerator generator = hazelcastServerInstance.getIdGenerator(IMDGDistributedNames.MAP_SEQUENCE_NAME);

View file

@ -157,8 +157,11 @@ public class QueueConsumer implements AutoCloseable {
@Override
public void close() {
log.debug("Closing queue consumer {}", getClass().getSimpleName());
closed.set(true);
consumer.wakeup();
inputExecutor.shutdown();
outputExecutor.shutdown();
}