Class WaitableInt
java.lang.Object
EDU.oswego.cs.dl.util.concurrent.SynchronizedVariable
EDU.oswego.cs.dl.util.concurrent.SynchronizedInt
EDU.oswego.cs.dl.util.concurrent.WaitableInt
- All Implemented Interfaces:
Executor, Cloneable, Comparable
A class useful for offloading waiting and signalling operations
on single int variables.
-
Field Summary
Fields inherited from class SynchronizedInt
value_Fields inherited from class SynchronizedVariable
lock_ -
Constructor Summary
ConstructorsConstructorDescriptionWaitableInt(int initialValue) Make a new WaitableInt with the given initial value, and using its own internal lock.WaitableInt(int initialValue, Object lock) Make a new WaitableInt with the given initial value, and using the supplied lock. -
Method Summary
Modifier and TypeMethodDescriptionintadd(int amount) Add amount to value (i.e., set value += amount)intand(int b) Set value to value & b.booleancommit(int assumedValue, int newValue) Set value to newValue only if it is currently assumedValue.intSet the value to its complementintDecrement the value.intdivide(int factor) Divide value by factor (i.e., set value /= factor)intIncrement the value.intmultiply(int factor) Multiply value by factor (i.e., set value *= factor)intor(int b) Set value to value | b.intset(int newValue) Set to newValue.intsubtract(int amount) Subtract amount from value (i.e., set value -= amount)voidWait until value equals c, then run action if nonnull.voidwhenGreater(int c, Runnable action) wait until value greater than c, then run action if nonnull.voidwhenGreaterEqual(int c, Runnable action) wait until value greater than or equal to c, then run action if nonnull.voidwait until value less than c, then run action if nonnull.voidwhenLessEqual(int c, Runnable action) wait until value less than or equal to c, then run action if nonnull.voidwhenNotEqual(int c, Runnable action) wait until value not equal to c, then run action if nonnull.intxor(int b) Set value to value ^ b.Methods inherited from class SynchronizedInt
compareTo, compareTo, compareTo, equals, get, hashCode, negate, swap, toStringMethods inherited from class SynchronizedVariable
execute, getLock
-
Constructor Details
-
WaitableInt
public WaitableInt(int initialValue) Make a new WaitableInt with the given initial value, and using its own internal lock. -
WaitableInt
Make a new WaitableInt with the given initial value, and using the supplied lock.
-
-
Method Details
-
set
public int set(int newValue) Description copied from class:SynchronizedIntSet to newValue.- Overrides:
setin classSynchronizedInt- Returns:
- the old value
-
commit
public boolean commit(int assumedValue, int newValue) Description copied from class:SynchronizedIntSet value to newValue only if it is currently assumedValue.- Overrides:
commitin classSynchronizedInt- Returns:
- true if successful
-
increment
public int increment()Description copied from class:SynchronizedIntIncrement the value.- Overrides:
incrementin classSynchronizedInt- Returns:
- the new value
-
decrement
public int decrement()Description copied from class:SynchronizedIntDecrement the value.- Overrides:
decrementin classSynchronizedInt- Returns:
- the new value
-
add
public int add(int amount) Description copied from class:SynchronizedIntAdd amount to value (i.e., set value += amount)- Overrides:
addin classSynchronizedInt- Returns:
- the new value
-
subtract
public int subtract(int amount) Description copied from class:SynchronizedIntSubtract amount from value (i.e., set value -= amount)- Overrides:
subtractin classSynchronizedInt- Returns:
- the new value
-
multiply
public int multiply(int factor) Description copied from class:SynchronizedIntMultiply value by factor (i.e., set value *= factor)- Overrides:
multiplyin classSynchronizedInt- Returns:
- the new value
-
divide
public int divide(int factor) Description copied from class:SynchronizedIntDivide value by factor (i.e., set value /= factor)- Overrides:
dividein classSynchronizedInt- Returns:
- the new value
-
complement
public int complement()Set the value to its complement- Overrides:
complementin classSynchronizedInt- Returns:
- the new value
-
and
public int and(int b) Set value to value & b.- Overrides:
andin classSynchronizedInt- Returns:
- the new value
-
or
public int or(int b) Set value to value | b.- Overrides:
orin classSynchronizedInt- Returns:
- the new value
-
xor
public int xor(int b) Set value to value ^ b.- Overrides:
xorin classSynchronizedInt- Returns:
- the new value
-
whenEqual
Wait until value equals c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenNotEqual
wait until value not equal to c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenLessEqual
wait until value less than or equal to c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenLess
wait until value less than c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenGreaterEqual
wait until value greater than or equal to c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-
whenGreater
wait until value greater than c, then run action if nonnull. The action is run with the synchronization lock held.- Throws:
InterruptedException
-