Merge pull request #6548 from alvasw/fix_dao_state_storage_service_shutdown_data_corruption_bug

DaoStateStorageService: Fix shutdown data corruption bug
This commit is contained in:
Alejandro García 2023-02-03 15:14:44 +00:00 committed by GitHub
commit f24e0f231d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 10 deletions

View file

@ -89,14 +89,27 @@ public class Utilities {
return getSingleThreadExecutor(name);
}
public static ExecutorService getNonDaemonSingleThreadExecutor(Class<?> aClass) {
String name = aClass.getSimpleName();
return getSingleThreadExecutor(name, false);
}
public static ExecutorService getSingleThreadExecutor(String name) {
final ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setNameFormat(name)
.setDaemon(true)
.build();
return getSingleThreadExecutor(name, true);
}
private static ExecutorService getSingleThreadExecutor(String name, boolean isDaemonThread) {
final ThreadFactory threadFactory = getThreadFactory(name, isDaemonThread);
return Executors.newSingleThreadExecutor(threadFactory);
}
private static ThreadFactory getThreadFactory(String name, boolean isDaemonThread) {
return new ThreadFactoryBuilder()
.setNameFormat(name)
.setDaemon(isDaemonThread)
.build();
}
public static ExecutorService getSingleThreadExecutor(ThreadFactory threadFactory) {
return Executors.newSingleThreadExecutor(threadFactory);
}

View file

@ -34,8 +34,6 @@ import bisq.common.util.Utilities;
import javax.inject.Inject;
import javax.inject.Named;
import com.google.common.util.concurrent.MoreExecutors;
import java.io.File;
import java.io.IOException;
@ -44,7 +42,6 @@ import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
@ -58,7 +55,7 @@ public class DaoStateStorageService extends StoreService<DaoStateStore> {
private final BsqBlocksStorageService bsqBlocksStorageService;
private final File storageDir;
private final LinkedList<Block> blocks = new LinkedList<>();
private final ExecutorService executorService = Utilities.getSingleThreadExecutor(this.getClass());
private final ExecutorService executorService = Utilities.getNonDaemonSingleThreadExecutor(this.getClass());
private Optional<Future<?>> future = Optional.empty();
@ -128,8 +125,7 @@ public class DaoStateStorageService extends StoreService<DaoStateStore> {
}
public void shutDown() {
// noinspection UnstableApiUsage
MoreExecutors.shutdownAndAwaitTermination(executorService, 10, TimeUnit.SECONDS);
executorService.shutdown();
}
@Override