EDU.oswego.cs.dl.util.concurrent

Class TimeoutSync

public class TimeoutSync extends Object implements Sync

A TimeoutSync is an adaptor class that transforms all calls to acquire to instead invoke attempt with a predetermined timeout value.

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");
 }
 

[ Introduction to this package. ]

See Also:

Field Summary
protected Syncsync_
protected longtimeout_
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
voidacquire()
booleanattempt(long msecs)
voidrelease()

Field Detail

sync_

protected final Sync sync_

timeout_

protected final long timeout_

Constructor Detail

TimeoutSync

public 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 Detail

acquire

public void acquire()

attempt

public boolean attempt(long msecs)

release

public void release()