Skip to content

Commit 7e75f54

Browse files
ChristophBodensteinChristophBodenstein
authored andcommitted
added correct thread synchronization for local simulation
1 parent 04a5c1a commit 7e75f54

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

TimeNETOptimizationEnvironment/src/toe/simulation/SimulatorLocal.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,12 @@ private void startLocalSimulation(String exportFileName) {
259259

260260
// Start new process
261261
timeStamp = Calendar.getInstance().getTimeInMillis();
262-
263262
nativeProcess myNativeProcess = new nativeProcess(processBuilder, this);
264-
265-
//We wait until the process is ended or aborted
266-
//TODO: Use thread synchronization with timeout!
267-
while (myNativeProcess.isRunning()) {
268-
Thread.sleep(500);
269-
if ((Calendar.getInstance().getTimeInMillis() - timeStamp) / 1000 >= maxTime) {
270-
support.log("Simulation took longer than given MaxTime! Will be aborted! " + " MaxTime was:" + maxTime.toString(), typeOfLogLevel.ERROR);
263+
synchronized (myNativeProcess) {
264+
try {
265+
myNativeProcess.wait(maxTime * 1000);
266+
} catch (Exception e) {
267+
support.log("Simulation may took longer than given MaxTime! Will be aborted! " + " MaxTime was:" + maxTime.toString(), typeOfLogLevel.ERROR);
271268
myNativeProcess.setKillProcess(true);
272269
}
273270
}

0 commit comments

Comments
 (0)