Skip to content

Commit 9f2b3e8

Browse files
committed
Limit max threads in pool. Use unbounded queue to pending tanks.
1 parent df3f207 commit 9f2b3e8

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

objectbox-java/src/main/java/io/objectbox/BoxStoreBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public class BoxStoreBuilder {
9393

9494
int threadPoolCoreSize = 0;
9595

96-
int threadPoolMaxSize = Integer.MAX_VALUE;
96+
int threadPoolMaxSize = Math.min(64, Runtime.getRuntime().availableProcessors());
9797

9898
int threadPoolThreadKeepAliveSeconds = 20;
9999

objectbox-java/src/main/java/io/objectbox/internal/ObjectBoxThreadPool.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package io.objectbox.internal;
1818

1919
import java.util.concurrent.Executors;
20-
import java.util.concurrent.SynchronousQueue;
20+
import java.util.concurrent.LinkedBlockingQueue;
2121
import java.util.concurrent.ThreadFactory;
2222
import java.util.concurrent.ThreadPoolExecutor;
2323
import java.util.concurrent.TimeUnit;
@@ -40,7 +40,7 @@ public class ObjectBoxThreadPool extends ThreadPoolExecutor {
4040
private final BoxStore boxStore;
4141

4242
public ObjectBoxThreadPool(BoxStore boxStore, int corePoolSize, int maximumPoolSize, int threadKeepAliveSeconds) {
43-
super(corePoolSize, maximumPoolSize, threadKeepAliveSeconds, TimeUnit.SECONDS, new SynchronousQueue<>(),
43+
super(corePoolSize, maximumPoolSize, threadKeepAliveSeconds, TimeUnit.SECONDS, new LinkedBlockingQueue<>(),
4444
new ObjectBoxThreadFactory());
4545
this.boxStore = boxStore;
4646
}

0 commit comments

Comments
 (0)