Skip to main content

2. An endless process

An endless process runs until an operator asks it to stop. It must check the library's cancellation signal and return promptly.

Register ticker​

Ticker.java
@SynapsysProcess(name = "ticker")
public class Ticker extends AbstractEndlessProcess {
@Override
protected void runForever(StopSignal stopSignal) throws Exception {
while (!stopSignal.isStopRequested()) {
System.out.println("tick");
Thread.sleep(2_000);
}
System.out.println("stopped cleanly");
}
}

Keep blocking intervals short enough for the stop requirement of your system.

Start and inspect it​

Restart the worker, open Processes, and choose Start for ticker. Within one heartbeat it reports running. Open Executions and its logs; new tick lines arrive through later heartbeats.

Stop it​

Choose Stop. The process first reports stopping, then idle after its body returns. If it remains in stopping, the body is blocked or is not observing the stop signal.

Commands carry increasing tokens. Repeated heartbeat responses cannot start a second copy because the worker applies only a token newer than the one it has acknowledged.