package de.domisum.lib.auxilium.util.java;

import java.time.Duration;

public abstract class Ticker
{

	// SETTINGS
	private Duration tickInterval;
	private String threadName;

	// STATUS
	private Thread tickThread;
	private boolean tickThreadRunning;


	// INIT
	protected Ticker(Duration tickInterval)
	{
		this(tickInterval, "ticker");
	}

	protected Ticker(Duration tickInterval, String threadName)
	{
		this.tickInterval = tickInterval;
		this.threadName = threadName;
	}


	// TICK
	public synchronized void start()
	{
		if(this.tickThread != null)
			return;

		this.tickThread = new Thread(()->{
			while(this.tickThreadRunning)
			{
				tick();
				ThreadUtil.sleep(this.tickInterval.toMillis());
			}
		});

		this.tickThread.setName(this.threadName);
		this.tickThreadRunning = true;
		this.tickThread.start();
	}

	public synchronized void stop()
	{
		if(this.tickThread == null)
			return;

		this.tickThreadRunning = false;
		this.tickThread.interrupt();
		if(Thread.currentThread() != this.tickThread)
			ThreadUtil.join(this.tickThread);
		this.tickThread = null;
	}


	protected abstract void tick();

}

@@ -852,24 +852,105 @@
 d stop()%0A%09%7B%0A
+%09%09requestStop();%0A%09%09waitForStop();%0A%09%7D%0A%0A%09public synchronized void requestStop()%0A%09%7B%0A
 %09%09if(this.ti
@@ -1044,16 +1044,105 @@
 rupt();%0A
+%09%7D%0A%0A%09public synchronized void waitForStop()%0A%09%7B%0A%09%09if(this.tickThread == null)%0A%09%09%09return;%0A%0A
 %09%09if(Thr

Split stop into request and waitfor (Ticker)