runTasks();
taskTime += System.nanoTime() - asd2;
- System.err.println(" st = " + 1e-9*stepTime + " tt = " + 1e-9*taskTime);
+ //System.err.println(" st = " + 1e-9*stepTime + " tt = " + 1e-9*taskTime);
while(obtainedRealtimeRatio > desiredRealtimeRatio) {
int ran = runTasks();
if(deltaNs > 0) {
synchronized(tasks) {
- try {
- tasks.wait(deltaMs, deltaNsRem);
- } catch (InterruptedException e) {
- e.printStackTrace();
+ if (inState(StandardExperimentStates.Running.class)) {
+ try {
+ tasks.wait(deltaMs, deltaNsRem);
+ } catch (InterruptedException e) {
+ LOGGER.warn("Dynamic experiment thread '" + this.getName() + "' (" + this.getClass().getName() + ") interrupted", e);
+ }
}
}
}
} else {
- while(!inState(StandardExperimentStates.Running.class) && inActiveState()) {
-
- synchronized(tasks) {
+ synchronized(tasks) {
+ while(!inState(StandardExperimentStates.Running.class) && inActiveState()) {
int ran = runTasks();
if(ran == 0) {
try {
tasks.wait(Integer.MAX_VALUE);
} catch (InterruptedException e) {
- e.printStackTrace();
+ LOGGER.warn("Dynamic experiment thread '" + this.getName() + "' (" + this.getClass().getName() + ") interrupted", e);
}
}
}
};
public int runTasks() {
- ArrayList<Runnable> todo = new ArrayList<>();
+ ArrayList<Runnable> todo = new ArrayList<>(tasks.size());
synchronized(tasks) {
todo.addAll(tasks);
tasks.clear();
public void changeState(ExperimentState state) {
this.state = state;
fireStateChanged(state);
+ synchronized (tasks) {
+ tasks.notifyAll();
+ }
}
public void addListener(DynamicExperimentThreadListener listener) {