common-util

local.tomas.util.sync
Class Mutex

java.lang.Object
  extended by local.tomas.util.sync.Mutex
All Implemented Interfaces:
SyncInterface

public class Mutex
extends Object
implements SyncInterface

A Mutex can be used to assert mutual exclusive access to a resource. It acts as a kind of synchronized boolean switch.

Version:
1.0
Author:
Tomas Teubner

Constructor Summary
Mutex()
          Default constructor.
 
Method Summary
 void lock()
          Lock object.
 boolean trylock()
          Try to lock object.
 void unlock()
          Unlock object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mutex

public Mutex()
Default constructor.

Method Detail

lock

public void lock()
          throws InterruptedException
Description copied from interface: SyncInterface
Lock object. Calls to this method will block until object can be locked.

Specified by:
lock in interface SyncInterface
Throws:
InterruptedException

trylock

public boolean trylock()
Description copied from interface: SyncInterface
Try to lock object. Calls to this method return immediately. Lock is performed if possible, otherwise false is returned.

Specified by:
trylock in interface SyncInterface
Returns:
true if lock succeeded, false otherwise

unlock

public void unlock()
Description copied from interface: SyncInterface
Unlock object.

Specified by:
unlock in interface SyncInterface

common-util

Copyright © 2005-2007 Tomas Teubner. All Rights Reserved.