nl.knowledgeplaza.util.thread
Class Semaphore

java.lang.Object
  extended by nl.knowledgeplaza.util.thread.Semaphore

public class Semaphore
extends java.lang.Object

A simple semaphore for multithreading issues.

Version:
$Revision: 1.2 $

Field Summary
static java.lang.String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
 
Constructor Summary
Semaphore(int n)
           
Semaphore(int n, boolean exitOnStopFlag)
           
 
Method Summary
 void acquire()
           
 boolean aquireNonBlocking()
           
 java.lang.String getName()
           
 int getValue()
          Get the current value, mostly for debugging purposes.
 void release()
           
 void setName(java.lang.String Name)
          name of the semaphore (default is hashCode)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SOURCECODE_VERSION

public static final java.lang.String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values
Constructor Detail

Semaphore

public Semaphore(int n)
Parameters:
n -

Semaphore

public Semaphore(int n,
                 boolean exitOnStopFlag)
Parameters:
n -
exitOnStopFlag - see ThreadUtils
Method Detail

setName

public void setName(java.lang.String Name)
name of the semaphore (default is hashCode)


getName

public java.lang.String getName()

acquire

public void acquire()

aquireNonBlocking

public boolean aquireNonBlocking()
Returns:
false is the aquire would have blocked, true if an aquire actually occured

release

public void release()

getValue

public int getValue()
Get the current value, mostly for debugging purposes. Beware: to not use this to create a check-and-aquire loop, that will create a whole in the logic. For such a algorithm, use the aquireNonBlocking.

Returns:
current value


Copyright © 2010 KnowledgePlaza. All Rights Reserved.