提交 1a79c0ac authored 作者: Noel Grandin's avatar Noel Grandin

limit size of thread pool

and shut it down when the store closes
上级 844f4f49
...@@ -23,10 +23,10 @@ import java.util.Map; ...@@ -23,10 +23,10 @@ import java.util.Map;
import java.util.PriorityQueue; import java.util.PriorityQueue;
import java.util.Queue; import java.util.Queue;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -309,6 +309,11 @@ public class MVStore { ...@@ -309,6 +309,11 @@ public class MVStore {
private long lastFreeUnusedChunks; private long lastFreeUnusedChunks;
/**
* Service for executing multiple reads in parallel when doing garbage collection.
*/
final ExecutorService executorService;
/** /**
* Create and open the store. * Create and open the store.
* *
...@@ -359,6 +364,8 @@ public class MVStore { ...@@ -359,6 +364,8 @@ public class MVStore {
keysPerPage = DataUtils.getConfigParam(config, "keysPerPage", 48); keysPerPage = DataUtils.getConfigParam(config, "keysPerPage", 48);
backgroundExceptionHandler = backgroundExceptionHandler =
(UncaughtExceptionHandler)config.get("backgroundExceptionHandler"); (UncaughtExceptionHandler)config.get("backgroundExceptionHandler");
executorService = new ThreadPoolExecutor(0, 10, 10L, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(keysPerPage + 1));
meta = new MVMap<>(this); meta = new MVMap<>(this);
meta.init(); meta.init();
if (this.fileStore != null) { if (this.fileStore != null) {
...@@ -945,6 +952,7 @@ public class MVStore { ...@@ -945,6 +952,7 @@ public class MVStore {
return; return;
} }
stopBackgroundThread(); stopBackgroundThread();
executorService.shutdownNow(); // no need to wait for reads
closed = true; closed = true;
storeLock.lock(); storeLock.lock();
try { try {
...@@ -1381,11 +1389,9 @@ public class MVStore { ...@@ -1381,11 +1389,9 @@ public class MVStore {
return collector.getReferenced(); return collector.getReferenced();
} }
final ExecutorService executorService = Executors.newCachedThreadPool();
final class ChunkIdsCollector { final class ChunkIdsCollector {
private final Set<Integer> referencedChunks = ConcurrentHashMap.newKeySet(); private final Set<Integer> referencedChunks = ConcurrentHashMap.<Integer>newKeySet();
private final ChunkIdsCollector parent; private final ChunkIdsCollector parent;
private int mapId; private int mapId;
......
...@@ -254,7 +254,7 @@ public abstract class Page implements Cloneable ...@@ -254,7 +254,7 @@ public abstract class Page implements Cloneable
*/ */
static List<Future<?>> readChildrenPositions(FileStore fileStore, long pos, static List<Future<?>> readChildrenPositions(FileStore fileStore, long pos,
long filePos, long maxPos, long filePos, long maxPos,
MVStore.ChunkIdsCollector collector, final MVStore.ChunkIdsCollector collector,
ExecutorService executorService) { ExecutorService executorService) {
ByteBuffer buff; ByteBuffer buff;
int maxLength = DataUtils.getPageMaxLength(pos); int maxLength = DataUtils.getPageMaxLength(pos);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论