java.util.concurrent package.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | ConcurrentUtils.
the type of the value wrapped by this class T>A specialized |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv static Throwable | Returns: a flag whether the passed in exception is a checked exceptionthe ex)Throwable to checkTests whether the specified |
| public static < the type of the value used by this T> FutureFuture object | Returns: an instance of Future that will return the value, never nullthe constant value to return, may be null value)Gets an implementation of |
| public static < the type of the keys of the map K, the type of the values of the map V> V | Returns: the value stored in the map after this operation; this may or may not be the object created by theConcurrentInitializerthe map to be modified map, final K the key of the value to be added key, final ConcurrentInitializer<V> the init)ConcurrentInitializer for creating the valueChecks if a concurrent map contains a key and creates a corresponding value if not. |
| public static < the type of the keys of the map K, the type of the values of the map V> V | Returns: the value stored in the map after this operation; this may or may not be the object created by theConcurrentInitializerthe map to be modified map, final K the key of the value to be added key, final ConcurrentInitializer<V> the init)ConcurrentInitializer for creating the valueChecks if a concurrent map contains a key and creates a corresponding value if not, suppressing checked exceptions. |
| public static ConcurrentException | Returns: aConcurrentException with the checked causethe exception to be processed ex)Inspects the cause of the specified |
| public static ConcurrentRuntimeException | Returns: aConcurrentRuntimeException with the checked causethe exception to be processed ex)Inspects the cause of the specified |
| public static void | handleCause(final ExecutionException
the exception to be handled ex)Handles the specified |
| public static void | handleCauseUnchecked(final ExecutionException
the exception to be handled ex)Handles the specified |
| public static < the type of the object produced by the initializer T> T | Returns: the object managed by theConcurrentInitializerthe initializer)ConcurrentInitializer to be invokedInvokes the specified |
| public static < the type of the object produced by the initializer T> T | Returns: the object managed by theConcurrentInitializerthe initializer)ConcurrentInitializer to be invokedInvokes the specified |
| public static < the type of the keys of the map K, the type of the values of the map V> V | Returns: the value stored in the map after this operationthe map to be modified map, final K the key of the value to be added key, final V the value to be added value)Puts a value in the specified |
| ConcurrentUtils | back to summary |
|---|---|
| private ConcurrentUtils() Private constructor so that no instances can be created. This class contains only static utility methods. | |
| checkedException | back to summary |
|---|---|
| pack-priv static Throwable checkedException(final Throwable ex) Tests whether the specified
| |
| constantFuture | back to summary |
|---|---|
| public static <T> Future Gets an implementation of This can be useful to return a simple constant immediately from the concurrent processing, perhaps as part of avoiding nulls. A constant future can also be useful in testing. | |
| createIfAbsent | back to summary |
|---|---|
| public static <K, V> V createIfAbsent(final ConcurrentMap<K, V> map, final K key, final ConcurrentInitializer<V> init) throws ConcurrentException Checks if a concurrent map contains a key and creates a corresponding
value if not. This method first checks the presence of the key in the
given map. If it is already contained, its value is returned. Otherwise
the
| |
| createIfAbsentUnchecked | back to summary |
|---|---|
| public static <K, V> V createIfAbsentUnchecked(final ConcurrentMap<K, V> map, final K key, final ConcurrentInitializer<V> init) Checks if a concurrent map contains a key and creates a corresponding
value if not, suppressing checked exceptions. This method calls
| |
| extractCause | back to summary |
|---|---|
| public static ConcurrentException extractCause(final ExecutionException ex) Inspects the cause of the specified
| |
| extractCauseUnchecked | back to summary |
|---|---|
| public static ConcurrentRuntimeException extractCauseUnchecked(final ExecutionException ex) Inspects the cause of the specified
| |
| handleCause | back to summary |
|---|---|
| public static void handleCause(final ExecutionException ex) throws ConcurrentException Handles the specified
| |
| handleCauseUnchecked | back to summary |
|---|---|
| public static void handleCauseUnchecked(final ExecutionException ex) Handles the specified
| |
| initialize | back to summary |
|---|---|
| public static <T> T initialize(final ConcurrentInitializer<T> initializer) throws ConcurrentException Invokes the specified
| |
| initializeUnchecked | back to summary |
|---|---|
| public static <T> T initializeUnchecked(final ConcurrentInitializer<T> initializer) Invokes the specified
| |
| putIfAbsent | back to summary |
|---|---|
| public static <K, V> V putIfAbsent(final ConcurrentMap<K, V> map, final K key, final V value) Puts a value in the specified
if (!map.containsKey(key)) {
map.put(key, value);
return value;
} else {
return map.get(key);
}
except that the action is performed atomically. So this method always returns the value which is stored in the map. This method is null-safe: It accepts a null map as input without throwing an exception. In this case the return value is null, too.
| |
Future implementation which wraps a constant value.
| Modifier and Type | Field and Description |
|---|---|
| private final T | value
The constant value. |
| Access | Constructor and Description |
|---|---|
| pack-priv | ConstantFuture(final T
the value (may be null) value)Creates a new instance of |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | cancel(final boolean mayInterruptIfRunning)
Implements java. Attempts to cancel execution of this task. |
| public T | get()
Implements java. Waits if necessary for the computation to complete, and then retrieves its result. |
| public T | get(final long timeout, final TimeUnit unit)
Implements java. Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available. |
| public boolean | isCancelled()
Implements java. Returns |
| public boolean |
| value | back to summary |
|---|---|
| private final T value The constant value. | |
| ConstantFuture | back to summary |
|---|---|
| pack-priv ConstantFuture(final T value) Creates a new instance of
| |
| cancel | back to summary |
|---|---|
| public boolean cancel(final boolean mayInterruptIfRunning) Implements java. Doc from java. Attempts to cancel execution of this task. This method has no
effect if the task is already completed or cancelled, or could
not be cancelled for some other reason. Otherwise, if this
task has not started when The return value from this method does not necessarily
indicate whether the task is now cancelled; use
| |
| get | back to summary |
|---|---|
| public T get() Implements java. Doc from java. Waits if necessary for the computation to complete, and then retrieves its result. This implementation just returns the constant value.
| |
| get | back to summary |
|---|---|
| public T get(final long timeout, final TimeUnit unit) Implements java. Doc from java. Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available. This implementation just returns the constant value; it does not block, therefore the timeout has no meaning.
| |
| isCancelled | back to summary |
|---|---|
| public boolean isCancelled() Implements java. Doc from java. Returns
| |
| isDone | back to summary |
|---|---|
| public boolean isDone() Implements java. Doc from java. Returns
| |