autohit.utils
Class ObjectMonitor

java.lang.Object
  |
  +--autohit.utils.ObjectMonitor

public class ObjectMonitor
extends java.lang.Object

A simple object monitor that can be used as a mutex.


Constructor Summary
ObjectMonitor()
          Default constructor.
ObjectMonitor(int lock)
          Contructor.
 
Method Summary
 void lock(boolean lock)
          Lock or unlock the monitor.
 void ownNotify()
          This is a syncronized notify.
 void ownNotifyAll()
          This is a syncronized notifyAll.
 void ownWait()
          This is a syncronized wait.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectMonitor

public ObjectMonitor()
Default constructor. It will create the monitor that is unlocked.

ObjectMonitor

public ObjectMonitor(int lock)
Contructor. Allows you to set the lock on creation. I recommend against using this one... I bet you get yourself deadlocked. :D
Method Detail

lock

public void lock(boolean lock)
Lock or unlock the monitor. Trying to lock an already locked monitor will block the thread until the owning thread unlocks it. More than one thread can be waiting for the lock. So, watchout for deadlock!
Parameters:
lock - true locks, false unlocks.

ownNotify

public void ownNotify()
This is a syncronized notify. This way any thread can notify as the owner.

ownNotifyAll

public void ownNotifyAll()
This is a syncronized notifyAll.

ownWait

public void ownWait()
This is a syncronized wait. Interrupt exception is caught and discarded.