mandala.util
Class ThreadBarrier

java.lang.Object
  extended bymandala.util.ThreadBarrier
All Implemented Interfaces:
java.io.Serializable

public class ThreadBarrier
extends java.lang.Object
implements java.io.Serializable

Instance of this class are barrier for a specified number of threads.

A barrier is a data structure that blocks until a specified number of threads have reached it. In this case, the barrier is released and threads are notified so they can continue their run.

Version:
1.0
Author:
eipi
See Also:
Serialized Form

Field Summary
protected  int count
          The number of threads that must traverse this barrier before being unlocked.
protected  boolean released
          The released state of this barrier.
 
Constructor Summary
ThreadBarrier(int count)
          Creates a new ThreadBarrier instance.
 
Method Summary
 int getCount()
          Returns the number of threads that must traverse this barrier before releasing it.
 boolean isReleased()
          Returns the released state of this barrier.
 void reuse(int count)
          Reuse this instance as a new barrier.
 void synchronize()
          Wait until count threads have reached this barrier.
 boolean synchronize(long timeout)
          Wait until count threads have reached this barrier or the specified timeout expires.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

count

protected int count

The number of threads that must traverse this barrier before being unlocked.


released

protected boolean released

The released state of this barrier.

Constructor Detail

ThreadBarrier

public ThreadBarrier(int count)

Creates a new ThreadBarrier instance.

Parameters:
count - The number of threads that must traverse this barrier before being unlocked
Method Detail

getCount

public int getCount()

Returns the number of threads that must traverse this barrier before releasing it.

Returns:
the number of threads that must traverse this barrier before releasing it.


synchronize

public void synchronize()
                 throws java.lang.InterruptedException

Wait until count threads have reached this barrier.

Throws:
java.lang.InterruptedException - if an error occurs

synchronize

public boolean synchronize(long timeout)
                    throws java.lang.InterruptedException

Wait until count threads have reached this barrier or the specified timeout expires.

Parameters:
timeout - a long value
Returns:
true if this barrier is released, false otherwise.
Throws:
java.lang.InterruptedException - if an error occurs

isReleased

public boolean isReleased()

Returns the released state of this barrier.

Returns:
true if this barrier is released, false otherwise

reuse

public void reuse(int count)

Reuse this instance as a new barrier.

This method is a convenient way to prevent reallocation of a new ThreadBarrier object and eventually the work of the garbage collector to free the old one.

The count parameter is the same as in the constructor.

Throws:
java.lang.IllegalStateException - if this instance si not released.


Mandala help mailing list