Home » concurrent-sources » EDU.oswego.cs.dl.util.concurrent » [javadoc | source]
public class: SynchronizedVariable [javadoc | source]

All Implemented Interfaces:

Direct Known Subclasses:
    WaitableByte, WaitableRef, SynchronizedRef, WaitableBoolean, SynchronizedChar, WaitableDouble, SynchronizedFloat, WaitableChar, SynchronizedShort, SynchronizedDouble, SynchronizedLong, WaitableFloat, SynchronizedBoolean, WaitableLong, WaitableShort, WaitableInt, SynchronizedInt, SynchronizedByte

Base class for simple, small classes maintaining single values that are always accessed and updated under synchronization. Since defining them for only some types seemed too arbitrary, they exist for all basic types, although it is hard to imagine uses for some.

These classes mainly exist so that you do not have to go to the trouble of writing your own miscellaneous classes and methods in situations including:

While they cannot, by nature, share much code, all of these classes work in the same way.

Synchronized variables are always constructed holding an initial value of the associated type. Constructors also establish the lock to use for all methods:

Update methods
Each class supports several kinds of update methods:

Guarded methods
All Waitable subclasses provide notifications on every value update, and support guarded methods of the form whenpredicate, that wait until the predicate hold, then optionally run any Runnable action within the lock, and then return. All types support:

(If the action argument is null, these return immediately after the predicate holds.) Numerical types also support The Waitable classes are not always spectacularly efficient since they provide notifications on all value changes. They are designed for use in contexts where either performance is not an overriding issue, or where nearly every update releases guarded waits anyway.

Other methods
This class implements Executor, and provides an execute method that runs the runnable within the lock.

All classes except SynchronizedRef and WaitableRef implement Cloneable and Comparable. Implementations of the corresponding methods either use default mechanics, or use methods that closely correspond to their java.lang analogs. SynchronizedRef does not implement any of these standard interfaces because there are many cases where it would not make sense. However, you can easily make simple subclasses that add the appropriate declarations.

[ Introduction to this package. ]
Field Summary
protected final  Object lock_     
 public SynchronizedVariable() 
 public SynchronizedVariable(Object lock) 
    Create a SynchronizedVariable using the supplied lock
Method from EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable Summary:
execute,   getLock
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable Detail:
 public  void execute(Runnable command) throws InterruptedException 
    If current thread is not interrupted, execute the given command within this object's lock
 public Object getLock() 
    Return the lock used for all synchronization for this object