diff options
Diffstat (limited to 'language-web/src/test/java/tools/refinery/language/web/xtext/servlet/AwaitTerminationExecutorServiceProvider.java')
-rw-r--r-- | language-web/src/test/java/tools/refinery/language/web/xtext/servlet/AwaitTerminationExecutorServiceProvider.java | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/language-web/src/test/java/tools/refinery/language/web/xtext/servlet/AwaitTerminationExecutorServiceProvider.java b/language-web/src/test/java/tools/refinery/language/web/xtext/servlet/AwaitTerminationExecutorServiceProvider.java index 08230335..25bcec37 100644 --- a/language-web/src/test/java/tools/refinery/language/web/xtext/servlet/AwaitTerminationExecutorServiceProvider.java +++ b/language-web/src/test/java/tools/refinery/language/web/xtext/servlet/AwaitTerminationExecutorServiceProvider.java | |||
@@ -3,7 +3,6 @@ package tools.refinery.language.web.xtext.servlet; | |||
3 | import java.util.ArrayList; | 3 | import java.util.ArrayList; |
4 | import java.util.List; | 4 | import java.util.List; |
5 | import java.util.concurrent.ExecutorService; | 5 | import java.util.concurrent.ExecutorService; |
6 | import java.util.concurrent.TimeUnit; | ||
7 | 6 | ||
8 | import org.eclipse.xtext.ide.ExecutorServiceProvider; | 7 | import org.eclipse.xtext.ide.ExecutorServiceProvider; |
9 | 8 | ||
@@ -11,24 +10,33 @@ import com.google.inject.Singleton; | |||
11 | 10 | ||
12 | @Singleton | 11 | @Singleton |
13 | public class AwaitTerminationExecutorServiceProvider extends ExecutorServiceProvider { | 12 | public class AwaitTerminationExecutorServiceProvider extends ExecutorServiceProvider { |
14 | private List<ExecutorService> servicesToShutDown = new ArrayList<>(); | 13 | private List<RestartableCachedThreadPool> servicesToShutDown = new ArrayList<>(); |
15 | 14 | ||
16 | @Override | 15 | @Override |
17 | protected ExecutorService createInstance(String key) { | 16 | protected ExecutorService createInstance(String key) { |
18 | var instance = super.createInstance(key); | 17 | var instance = new RestartableCachedThreadPool(); |
19 | servicesToShutDown.add(instance); | 18 | synchronized (servicesToShutDown) { |
19 | servicesToShutDown.add(instance); | ||
20 | } | ||
20 | return instance; | 21 | return instance; |
21 | } | 22 | } |
22 | 23 | ||
24 | public void waitForAllTasksToFinish() { | ||
25 | synchronized (servicesToShutDown) { | ||
26 | for (var executorService : servicesToShutDown) { | ||
27 | executorService.waitForAllTasksToFinish(); | ||
28 | } | ||
29 | } | ||
30 | } | ||
31 | |||
23 | @Override | 32 | @Override |
24 | public void dispose() { | 33 | public void dispose() { |
25 | super.dispose(); | 34 | super.dispose(); |
26 | for (var executorService : servicesToShutDown) { | 35 | synchronized (servicesToShutDown) { |
27 | try { | 36 | for (var executorService : servicesToShutDown) { |
28 | executorService.awaitTermination(1, TimeUnit.SECONDS); | 37 | executorService.waitForTermination(); |
29 | } catch (InterruptedException e) { | ||
30 | // Continue normally. | ||
31 | } | 38 | } |
39 | servicesToShutDown.clear(); | ||
32 | } | 40 | } |
33 | } | 41 | } |
34 | } | 42 | } |