diff options
Diffstat (limited to 'subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/server/ThreadPoolExecutorServiceProvider.java')
-rw-r--r-- | subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/server/ThreadPoolExecutorServiceProvider.java | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/server/ThreadPoolExecutorServiceProvider.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/server/ThreadPoolExecutorServiceProvider.java index 625909b9..ff8f4943 100644 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/server/ThreadPoolExecutorServiceProvider.java +++ b/subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/server/ThreadPoolExecutorServiceProvider.java | |||
@@ -9,6 +9,9 @@ import com.google.inject.Singleton; | |||
9 | import org.eclipse.xtext.ide.ExecutorServiceProvider; | 9 | import org.eclipse.xtext.ide.ExecutorServiceProvider; |
10 | import org.eclipse.xtext.web.server.model.XtextWebDocumentAccess; | 10 | import org.eclipse.xtext.web.server.model.XtextWebDocumentAccess; |
11 | import org.jetbrains.annotations.NotNull; | 11 | import org.jetbrains.annotations.NotNull; |
12 | import org.slf4j.Logger; | ||
13 | import org.slf4j.LoggerFactory; | ||
14 | import tools.refinery.language.web.generator.ModelGenerationService; | ||
12 | import tools.refinery.language.web.semantics.SemanticsService; | 15 | import tools.refinery.language.web.semantics.SemanticsService; |
13 | 16 | ||
14 | import java.lang.invoke.MethodHandle; | 17 | import java.lang.invoke.MethodHandle; |
@@ -25,6 +28,7 @@ import java.util.concurrent.atomic.AtomicInteger; | |||
25 | 28 | ||
26 | @Singleton | 29 | @Singleton |
27 | public class ThreadPoolExecutorServiceProvider extends ExecutorServiceProvider { | 30 | public class ThreadPoolExecutorServiceProvider extends ExecutorServiceProvider { |
31 | private static final Logger LOG = LoggerFactory.getLogger(ThreadPoolExecutorServiceProvider.class); | ||
28 | private static final String DOCUMENT_LOCK_EXECUTOR; | 32 | private static final String DOCUMENT_LOCK_EXECUTOR; |
29 | private static final AtomicInteger POOL_ID = new AtomicInteger(1); | 33 | private static final AtomicInteger POOL_ID = new AtomicInteger(1); |
30 | 34 | ||
@@ -33,6 +37,7 @@ public class ThreadPoolExecutorServiceProvider extends ExecutorServiceProvider { | |||
33 | private final int executorThreadCount; | 37 | private final int executorThreadCount; |
34 | private final int lockExecutorThreadCount; | 38 | private final int lockExecutorThreadCount; |
35 | private final int semanticsExecutorThreadCount; | 39 | private final int semanticsExecutorThreadCount; |
40 | private final int generatorExecutorThreadCount; | ||
36 | 41 | ||
37 | static { | 42 | static { |
38 | var lookup = MethodHandles.lookup(); | 43 | var lookup = MethodHandles.lookup(); |
@@ -57,7 +62,18 @@ public class ThreadPoolExecutorServiceProvider extends ExecutorServiceProvider { | |||
57 | public ThreadPoolExecutorServiceProvider() { | 62 | public ThreadPoolExecutorServiceProvider() { |
58 | executorThreadCount = getCount("REFINERY_XTEXT_THREAD_COUNT").orElse(0); | 63 | executorThreadCount = getCount("REFINERY_XTEXT_THREAD_COUNT").orElse(0); |
59 | lockExecutorThreadCount = getCount("REFINERY_XTEXT_LOCKING_THREAD_COUNT").orElse(executorThreadCount); | 64 | lockExecutorThreadCount = getCount("REFINERY_XTEXT_LOCKING_THREAD_COUNT").orElse(executorThreadCount); |
60 | semanticsExecutorThreadCount = getCount("REFINERY_XTEXT_SEMANTICS_THREAD_COUNT").orElse(executorThreadCount); | 65 | int semanticsCount = getCount("REFINERY_XTEXT_SEMANTICS_THREAD_COUNT").orElse(0); |
66 | if (semanticsCount == 0 || executorThreadCount == 0) { | ||
67 | semanticsExecutorThreadCount = 0; | ||
68 | } else { | ||
69 | semanticsExecutorThreadCount = Math.max(semanticsCount, executorThreadCount); | ||
70 | } | ||
71 | if (semanticsExecutorThreadCount != semanticsCount) { | ||
72 | LOG.warn("Setting REFINERY_XTEXT_SEMANTICS_THREAD_COUNT to {} to avoid deadlock. This value must be " + | ||
73 | "either 0 or at least as large as REFINERY_XTEXT_THREAD_COUNT to avoid lock contention.", | ||
74 | semanticsExecutorThreadCount); | ||
75 | } | ||
76 | generatorExecutorThreadCount = getCount("REFINERY_MODEL_GENERATION_THREAD_COUNT").orElse(executorThreadCount); | ||
61 | } | 77 | } |
62 | 78 | ||
63 | private static Optional<Integer> getCount(String name) { | 79 | private static Optional<Integer> getCount(String name) { |
@@ -94,6 +110,8 @@ public class ThreadPoolExecutorServiceProvider extends ExecutorServiceProvider { | |||
94 | private int getSize(String key) { | 110 | private int getSize(String key) { |
95 | if (SemanticsService.SEMANTICS_EXECUTOR.equals(key)) { | 111 | if (SemanticsService.SEMANTICS_EXECUTOR.equals(key)) { |
96 | return semanticsExecutorThreadCount; | 112 | return semanticsExecutorThreadCount; |
113 | } else if (ModelGenerationService.MODEL_GENERATION_EXECUTOR.equals(key)) { | ||
114 | return generatorExecutorThreadCount; | ||
97 | } else if (DOCUMENT_LOCK_EXECUTOR.equals(key)) { | 115 | } else if (DOCUMENT_LOCK_EXECUTOR.equals(key)) { |
98 | return lockExecutorThreadCount; | 116 | return lockExecutorThreadCount; |
99 | } else { | 117 | } else { |