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

com.github.akurilov.commons.concurrent.StoppableTaskBase Maven / Gradle / Ivy

There is a newer version: 2.3.6
Show newest version
package com.github.akurilov.commons.concurrent;

import java.io.IOException;

/**
 The base for a stoppable task
 */
public abstract class StoppableTaskBase
implements StoppableTask {

	private volatile boolean isClosedFlag = false;

	@Override
	public void close()
	throws IOException {
		isClosedFlag = true;
		doClose();
	}

	@Override
	public void run() {
		if(!isClosedFlag) {
			invoke();
		}
	}

	@Override
	public final boolean isClosed() {
		return isClosedFlag;
	}

	/**
	 * The task invocation method. Will not run if the task is stopped (closed).
	 */
	protected abstract void invoke();

	/**
	 * Implement this method for the cleanup purposes.
	 * @throws IOException
	 */
	protected abstract void doClose()
	throws IOException;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy