public class Mutex extends Object
This object may be used to obtain an exclusive lock around a piece of code. The first call to aquire will obtain the lock. All later calls with the same lock object will wait until release is called. This can be used to ensure that expensive code is only run once. Typical use is to protect code that generate objects to be put in some sort of cache.
Created: Sun Jul 29 11:37:56 2001
Modifier and Type | Class and Description |
---|---|
class |
Mutex.WaitObject |
Modifier and Type | Field and Description |
---|---|
protected static org.apache.log4j.Category |
CAT |
static long |
MAX_BLOCKING_TIME
Max time the lock will be held if aquire is called with
blocking false.
|
Constructor and Description |
---|
Mutex() |
Modifier and Type | Method and Description |
---|---|
void |
aquire(Object o)
Aquire lock with blocking and infinite timeout.
|
boolean |
aquire(Object o,
boolean blocking)
Aquire lock on object.
|
void |
aquire(Object o,
int timeout)
Aquire lock on object.
|
boolean |
aquire(Object o,
long timeout,
boolean blocking)
Aquire lock on object.
|
void |
release(Object o)
Release lock on object.
|
protected static final org.apache.log4j.Category CAT
public static final long MAX_BLOCKING_TIME
public void release(Object o)
o
- Release lock on this objectpublic void aquire(Object o) throws InterruptedException
o
- The object to aquire lock on.InterruptedException
public void aquire(Object o, int timeout) throws InterruptedException
o
- The object to aquire lock on.timeout
- Wait this long for object to become.
available. When timeout is reached, this threaf will steal
the lock and return. All other threads will be kept waiting.InterruptedException
public boolean aquire(Object o, boolean blocking) throws InterruptedException
o
- The object to aquire lock on.blocking
- Set this to false for this method not to
block. If blocking is false, the lock will be held for max
MAX_BLOCKING_TIME milliseconds.InterruptedException
public boolean aquire(Object o, long timeout, boolean blocking) throws InterruptedException
o
- The object to aquire lock on.timeout
- Wait this long for object to become
available. When timeout is reached, this threaf will steal
the lock and return. All other threads will be kept waiting.blocking
- Set this to false for this method not to
block. If blocking is false, the lock will be held for max
MAX_BLOCKING_TIME milliseconds.InterruptedException
© 1998- 2018 Stibo DX