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

com.leonarduk.clearcheckbook.processor.parallel.MonitorThread Maven / Gradle / Ivy

Go to download

A Java library to access the HTTP developer API for Clearcheckbook.com, the money management website.

There is a newer version: 1.4
Show newest version
/**
 * MonitorThread
 *
 * @author ${author}
 * @since 10-Jul-2016
 */
package com.leonarduk.clearcheckbook.processor.parallel;

import java.util.concurrent.ThreadPoolExecutor;

import org.apache.log4j.Logger;

/**
 * The Class MonitorThread.
 */
public class MonitorThread implements Runnable {

	/** The Constant _logger. */
	private static final Logger _logger = Logger.getLogger(MonitorThread.class);

	/** The executor. */
	private final ThreadPoolExecutor executor;

	/** The seconds. */
	private final int seconds;

	/** The run. */
	private boolean run = true;

	/**
	 * Instantiates a new monitor thread.
	 *
	 * @param executor
	 *            the executor
	 * @param delay
	 *            the delay
	 */
	public MonitorThread(final ThreadPoolExecutor executor, final int delay) {
		this.executor = executor;
		this.seconds = delay;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Runnable#run()
	 */
	@Override
	public void run() {
		while (this.run) {
			MonitorThread._logger.debug(String.format(
			        "[monitor] [%d/%d] Active: %d, Completed: %d, Task: %d, isShutdown: %s, isTerminated: %s",
			        this.executor.getPoolSize(), this.executor.getCorePoolSize(),
			        this.executor.getActiveCount(), this.executor.getCompletedTaskCount(),
			        this.executor.getTaskCount(), this.executor.isShutdown(),
			        this.executor.isTerminated()));
			try {
				Thread.sleep(this.seconds * 1000);
			}
			catch (final InterruptedException e) {
				e.printStackTrace();
			}
		}

	}

	/**
	 * Shutdown.
	 */
	public void shutdown() {
		this.run = false;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy