All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xy.reflect.ui.util.DelayedUpdateProcess Maven / Gradle / Ivy

package xy.reflect.ui.util;

public abstract class DelayedUpdateProcess {

	private boolean updateActionInQueue;
	private Object updateMutex = new Object();
	private long delayMilliseconds = 500;

	protected abstract void run();

	public long getDelayMilliseconds() {
		return delayMilliseconds;
	}

	public void setDelayMilliseconds(long delayMilliseconds) {
		this.delayMilliseconds = delayMilliseconds;
	}

	public void schedule() {
		if (updateActionInQueue) {
			return;
		}
		updateActionInQueue = true;
		new Thread("DelayedUpdateProcessor[of=" + DelayedUpdateProcess.this + "]") {
			@Override
			public void run() {
				synchronized (updateMutex) {
					try {
						sleep(delayMilliseconds);
					} catch (InterruptedException e) {
						throw new AssertionError(e);
					}
					updateActionInQueue = false;
					DelayedUpdateProcess.this.run();
				}
			}
		}.start();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy