ActiveMonitor

public class ActiveMonitor

ActiveMonitor is a thread monitor of active threads.

Author:Hugo Y. K. Lam

See also: ActiveThread

Constructors

ActiveMonitor

public ActiveMonitor()

Creares a new instance of ActiveMonitor.

Methods

acquireThread

public synchronized ActiveThread acquireThread()

Acquires a new active thread. This method will block if the maximum number of threads has been reached.

Returns:a new active thread or null if the monitor is suspended.

getMaxThreadCount

public int getMaxThreadCount()

Gets the maximum number of threads this monitor allows to acquire.

Returns:the maximum number.

getPeekThreadCount

public int getPeekThreadCount()

Gets the peek number of threads being acquired.

Returns:the peek number of threads being acquired.

getThreadCount

public int getThreadCount()

Gets the current number of threads being acquired.

Returns:the current number of threads being acquired.

releaseThread

public synchronized void releaseThread(ActiveThread thread)

Releases a previously acquired thread.

Parameters:
  • thread – the previously acquired thread.

resume

public synchronized void resume()

Resumes this monitor.

setMaxThreadCount

public void setMaxThreadCount(int maxThreadCount)

Sets the maximum number of threads this monitor allows to acquire.

Parameters:
  • maxThreadCount – the maximum number.

suspend

public synchronized void suspend()

Suspends this monitor.

See also: .waitForEmpty()

waitForEmpty

public synchronized void waitForEmpty()

Waits until all the acquired threads have been released.