org.sapia.ubik.net
Class Semaphore

java.lang.Object
  extended by org.sapia.ubik.net.Semaphore

public class Semaphore
extends java.lang.Object

This class implements a simple semaphore.

Author:
Yanick Duchesne
Copyright:
Copyright © 2002-2003 Sapia Open Source Software. All Rights Reserved.
License:
Read the license.txt file of the jar or visit the license page at the Sapia OSS web site

Nested Class Summary
static class Semaphore.SemaphoreRunnable
           
 
Field Summary
static int NO_MAX
           
 
Constructor Summary
Semaphore(int maxThread)
          Creates a new instance of this class.
Semaphore(int maxThread, ThreadFactory fac)
          Creates a new instance of this class.
 
Method Summary
 java.lang.Thread acquireFor(java.lang.Runnable r)
          Returns a thread that wraps the given runnable.
 int getThreadCount()
          Gets the number of currently running threads that have been borrowed from this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_MAX

public static final int NO_MAX
See Also:
Constant Field Values
Constructor Detail

Semaphore

public Semaphore(int maxThread)
Creates a new instance of this class.

Parameters:
maxThread - the number of threads this instance will be allowed to create.

Semaphore

public Semaphore(int maxThread,
                 ThreadFactory fac)
Creates a new instance of this class.

Parameters:
maxThread - the number of threads this instance will be allowed to create.
fac - a ThreadFactory instance.
Method Detail

getThreadCount

public int getThreadCount()
Gets the number of currently running threads that have been borrowed from this instance.

Returns:
the number of currently running threads.

acquireFor

public java.lang.Thread acquireFor(java.lang.Runnable r)
                            throws MaxThreadReachedException
Returns a thread that wraps the given runnable. The returned thread is not yet started.

This method uses this semaphore's internal thread factory to create the thread objects - the factory implementation can be specified at semaphore construction time.

Returns:
a Thread instance.
Throws:
MaxThreadReachedException


Copyright © 2010 Sapia OSS. All Rights Reserved.