Require that you have at least 1G per thread as each of them can require quite a lot during expression parsing.
@@ -221,9 +221,12 @@ public class TenantRepository {
}
private ExecutorService createModelBuilderExecutor(int numThreads) {
+ final long GB = 1024*1024*1024;
if (numThreads == 0) return new InThreadExecutorService();
if (numThreads < 0) {
- numThreads = Runtime.getRuntime().availableProcessors();
+ long maxHeap = Runtime.getRuntime().maxMemory();
+ int maxThreadsToFitInMemory = (int)(maxHeap / 1*GB);
+ numThreads = Math.min(Runtime.getRuntime().availableProcessors(), maxThreadsToFitInMemory);
}
return Executors.newFixedThreadPool(numThreads, ThreadFactoryFactory.getDaemonThreadFactory("deploy-helper"));
}
