ibis.util
Class Monitor

java.lang.Object
  extended byibis.util.Monitor

public final class Monitor
extends java.lang.Object

Monitor synchronization construct. The Monitor can be entered (lock()) and exited (unlock()). ConditionVariables that are part of this monitor can be obtained by createCV(). The Monitor has optional support for priority locking. If the Monitor is unlocked and some thread has locked it with priority = true, that thread has preference in waking up above nonpriority lockers.


Constructor Summary
Monitor()
          Constructs a Monitor, without support for priority locking.
Monitor(boolean priority)
          Constructs a Monitor.
 
Method Summary
 void checkImNotOwner()
          When debugging is enabled, throws an exception when the current thread owns the Monitor.
 void checkImOwner()
          When debugging is enabled, throws an exception when the current thread does not own the Monitor.
 ConditionVariable createCV()
          Creates a ConditionVariable associated with this Monitor.
 ConditionVariable createCV(boolean interruptible)
          Creates a ConditionVariable associated with this Monitor.
 java.lang.Thread getOwner()
           
 void lock()
          Enters the Monitor, without priority over other threads.
 void lock(boolean priority)
          Enters the Monitor.
static void report(java.io.PrintStream out)
          When statistics are enabled, this method prints some on the stream given.
 boolean tryLock()
           
 void unlock()
          Leaves the Monitor, making it available for other threads.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Monitor

public Monitor(boolean priority)
Constructs a Monitor. The parameter indicates wether it must have support for priority locking.

Parameters:
priority - when true, priority locking will be supported.

Monitor

public Monitor()
Constructs a Monitor, without support for priority locking.

Method Detail

lock

public void lock()
Enters the Monitor, without priority over other threads.


lock

public void lock(boolean priority)
Enters the Monitor. The parameter indicates wether this thread has priority over nonpriority lockers. This means that when the lock is released, this thread will get the lock before nonpriority lockers.

Parameters:
priority - when true, this thread has priority over nonpriority lockers.

tryLock

public boolean tryLock()

unlock

public void unlock()
Leaves the Monitor, making it available for other threads.


createCV

public ConditionVariable createCV()
Creates a ConditionVariable associated with this Monitor.

Returns:
the ConditionVariable created.

createCV

public ConditionVariable createCV(boolean interruptible)
Creates a ConditionVariable associated with this Monitor.

Parameters:
interruptible - when true, Thread.interrupt()ing the Thread that is waiting on this Condition Variable causes the waiting thread to return with an InterruptedException. Non-interruptible Condition Variables ignore Thread.interrupt().

checkImOwner

public final void checkImOwner()
When debugging is enabled, throws an exception when the current thread does not own the Monitor.

Throws:
IllegalLockStateException - is thrown when the current thread does not own the Monitor.

checkImNotOwner

public final void checkImNotOwner()
When debugging is enabled, throws an exception when the current thread owns the Monitor.

Throws:
IllegalLockStateException - is thrown when the current thread owns the Monitor.

report

public static void report(java.io.PrintStream out)
When statistics are enabled, this method prints some on the stream given.

Parameters:
out - the stream to print on.

getOwner

public java.lang.Thread getOwner()


The Ibis project