nl.knowledgeplaza.util.thread
Class Semaphore

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

public class Semaphore
extends Object

A simple semaphore for multithreading issues.

Version:
$Revision: 1.2 $

Field Summary
static 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()
           
 String getName()
           
 int getValue()
          Get the current value, mostly for debugging purposes.
 void release()
           
 void setName(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 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(String Name)
name of the semaphore (default is hashCode)


getName

public 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 © 2012 KnowledgePlaza. All Rights Reserved.