passing a lambda expression to thread constructor

This commit is contained in:
hneemann 2017-03-27 19:05:26 +02:00
parent deff384e03
commit 25036d0169

View File

@ -116,30 +116,27 @@ public class RealTimeClock implements ModelStateObserver {
private final Thread thread; private final Thread thread;
ThreadRunner() { ThreadRunner() {
thread = new Thread() { thread = new Thread(() -> {
@Override LOGGER.debug("thread start");
public void run() { long time = System.currentTimeMillis();
LOGGER.debug("thread start"); long counter = 0;
long time = System.currentTimeMillis(); try {
long counter = 0; while (!Thread.interrupted()) {
try { modelSync.accessNEx(() -> {
while (!interrupted()) { output.setValue(1 - output.getValue());
modelSync.accessNEx(() -> { model.doStep();
output.setValue(1 - output.getValue()); });
model.doStep(); counter++;
});
counter++;
}
} catch (NodeException e1) {
stopper.showErrorAndStopModel(Lang.get("msg_clockError"), e1);
} }
time = System.currentTimeMillis() - time; } catch (NodeException e1) {
stopper.showErrorAndStopModel(Lang.get("msg_clockError"), e1);
final long l = counter / time / 2;
status.setStatus(l + "kHz");
LOGGER.debug("thread end, f="+l+"kHz");
} }
}; time = System.currentTimeMillis() - time;
final long l = counter / time / 2;
status.setStatus(l + "kHz");
LOGGER.debug("thread end, f=" + l + "kHz");
});
thread.setDaemon(true); thread.setDaemon(true);
thread.start(); thread.start();
} }