EDU.oswego.cs.dl.util.concurrent
public class TimeoutSync extends Object implements Sync
Sample Usage. A TimeoutSync can be used to obtain Timeouts for locks used in SyncCollections. For example:
Mutex lock = new Mutex();
TimeoutSync timedLock = new TimeoutSync(lock, 1000); // 1 sec timeouts
Set set = new SyncSet(new HashSet(), timedlock);
try {
set. add("hi");
}
// SyncSets translate timeouts and other lock failures
// to unsupported operation exceptions,
catch (UnsupportedOperationException ex) {
System.out.println("Lock failure");
}
| Field Summary | |
|---|---|
| protected Sync | sync_ |
| protected long | timeout_ |
| Constructor Summary | |
|---|---|
| TimeoutSync(Sync sync, long timeout)
Create a TimeoutSync using the given Sync object, and
using the given timeout value for all calls to acquire.
| |
| Method Summary | |
|---|---|
| void | acquire() |
| boolean | attempt(long msecs) |
| void | release() |