]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Wake DynamicExperimentThread task runner up when state changes 53/2453/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 12 Nov 2018 12:35:16 +0000 (14:35 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 12 Nov 2018 12:35:35 +0000 (12:35 +0000)
Prevents the thread from getting stuck when it is shut down from stopped
state.

gitlab #194

Change-Id: Iaf5ad6238aae8925c42d029078ea5f2a2ffa3e8c

bundles/org.simantics.simulator.toolkit/src/org/simantics/simulator/toolkit/DynamicExperimentThread.java

index 9ee57f51055aec994a49d33f08726fec5a21c9ca..bff9fe751b666455b8c9655ad3b59e93fe807c98 100644 (file)
@@ -190,7 +190,7 @@ abstract public class DynamicExperimentThread extends Thread {
        };
 
        public int runTasks() {
-               ArrayList<Runnable> todo = new ArrayList<>();
+               ArrayList<Runnable> todo = new ArrayList<>(tasks.size());
                synchronized(tasks) {
                        todo.addAll(tasks);
                        tasks.clear();
@@ -273,6 +273,9 @@ abstract public class DynamicExperimentThread extends Thread {
        public void changeState(ExperimentState state) {
                this.state = state;
                fireStateChanged(state);
+               synchronized (tasks) {
+                       tasks.notifyAll();
+               }
        }
 
        public void addListener(DynamicExperimentThreadListener listener) {