java.concurrent, JDK 6における新機能

  
----------------------------------------------------------------------------
▼ブロックするデックです
java.util.concurrent
Interface BlockingDeque<E>

Type Parameters:
    E - the type of elements held in this collection

All Superinterfaces:
    BlockingQueue<E>, Collection<E>, Deque<E>, Iterable<E>, Queue<E>

All Known Implementing Classes:
    LinkedBlockingDeque

public interface BlockingDeque<E>
extends BlockingQueue<E>, Deque<E>

A Deque that additionally supports blocking operations that wait for the
deque to become non-empty when retrieving an element, and wait for space to
become available in the deque when storing an element. 

----------------------------------------------------------------------------
▼近似探索ができるマップです
java.util
interface NavigableMap<K,V>

Type Parameters:
    K - the type of keys maintained by this map
    V - the type of mapped values

All Superinterfaces:
    Map<K,V>, SortedMap<K,V>

All Known Subinterfaces:
    ConcurrentNavigableMap<K,V>

All Known Implementing Classes:
    ConcurrentSkipListMap, TreeMap

public interface NavigableMap<K,V>
extends SortedMap<K,V>

A SortedMap extended with navigation methods returning the closest matches
for given search targets. Methods lowerEntry, floorEntry, ceilingEntry, and
higherEntry return Map.Entry objects associated with keys respectively less
than, less than or equal, greater than or equal, and greater than a given
key, returning null if there is no such key. Similarly, methods lowerKey,
floorKey, ceilingKey, and higherKey return only the associated keys. All of
these methods are designed for locating, not traversing entries. 

-----------------------------------------------------------------------------
▼RunnableでもあるFutureです(FutureTaskもこれをimplements)
 「Java並行処理プログラミング」7-1-7を見てください
java.util.concurrent
Interface RunnableFuture<V>

Type Parameters:
    V - The result type returned by this Future's get method

All Superinterfaces:
    Future<V>, Runnable

All Known Subinterfaces:
    RunnableScheduledFuture<V>

All Known Implementing Classes:
    FutureTask, SwingWorker

public interface RunnableFuture<V>
extends Runnable, Future<V>

A Future that is Runnable. Successful execution of the run method causes
completion of the Future and allows access to its results.

ExecutorServiceのsubmit()が返すFutureTaskのrun()メソッドは、submitに渡された
Callableのcall()を呼んでいるだけです。
[参考記事]

-----------------------------------------------------------------------------
java.util.concurrent
Interface RunnableScheduledFuture<V>

Type Parameters:
    V - The result type returned by this Future's get method

All Superinterfaces:
    Comparable, Delayed, Future<V>, Runnable, RunnableFuture<V>, ScheduledFuture<V>

public interface RunnableScheduledFuture<V>
extends RunnableFuture<V>, ScheduledFuture<V>

A ScheduledFuture that is Runnable. Successful execution of the run method
causes completion of the Future and allows access to its results. 

-----------------------------------------------------------------------------
▼Futureをカスタマイズします
 「Java並行処理プログラミング」7-1-7を見てください
AbstractExecutorService.
newTaskFor

protected <T> RunnableFuture<T> newTaskFor(Runnable runnable,
                                           T value)

    Returns a RunnableFuture for the given runnable and default value.

    Parameters:
        runnable - the runnable task being wrapped
        value - the default value for the returned future 
    Returns:
        a RunnableFuture which when run will run the underlying runnable
and which, as a Future, will yield the given value as its result and
provide for cancellation of the underlying task.

-----------------------------------------------------------------------------
AbstractExecutorService.
newTaskFor

protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable)

    Returns a RunnableFuture for the given callable task.

    Parameters:
        callable - the callable task being wrapped 
    Returns:
        a RunnableFuture which when run will call the underlying callable
and which, as a Future, will yield the callable's result as its result and
provide for cancellation of the underlying task.

-----------------------------------------------------------------------------
▼新しいコンストラクタ
ConcurrentHashMap.
ConcurrentHashMap

public ConcurrentHashMap(int initialCapacity,
                         float loadFactor)

    Creates a new, empty map with the specified initial capacity and load
factor and with the default concurrencyLevel (16).

    Parameters:
        initialCapacity - The implementation performs internal sizing to
accommodate this many elements.
        loadFactor - the load factor threshold, used to control resizing.
Resizing may be performed when the average number of elements per bin
exceeds this threshold. 
    Throws:
        IllegalArgumentException - if the initial capacity of elements is
negative or the load factor is nonpositive

-----------------------------------------------------------------------------
▼NavigableMap, ConcurrentNavigableMapの実装です
java.util.concurrent
Class ConcurrentSkipListMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.concurrent.ConcurrentSkipListMap<K,V>

Type Parameters:
    K - the type of keys maintained by this map
    V - the type of mapped values

All Implemented Interfaces:
    Serializable, Cloneable, ConcurrentMap<K,V>,
    ConcurrentNavigableMap<K,V>, Map<K,V>, NavigableMap<K,V>, SortedMap<K,V>

public class ConcurrentSkipListMap<K,V>
extends AbstractMap<K,V>
implements ConcurrentNavigableMap<K,V>, Cloneable, Serializable

A scalable concurrent ConcurrentNavigableMap implementation. The map is
sorted according to the natural ordering of its keys, or by a Comparator
provided at map creation time, depending on which constructor is used.

This class implements a concurrent variant of SkipLists providing expected
average log(n) time cost for the containsKey, get, put and remove
operations and their variants. Insertion, removal, update, and access
operations safely execute concurrently by multiple threads. Iterators are
weakly consistent, returning elements reflecting the state of the map at
some point at or since the creation of the iterator. They do not throw
ConcurrentModificationException, and may proceed concurrently with other
operations. Ascending key ordered views and their iterators are faster than
descending ones. 

-----------------------------------------------------------------------------
java.util.concurrent
Class ConcurrentSkipListSet<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<E>
          extended by java.util.concurrent.ConcurrentSkipListSet<E>

Type Parameters:
    E - the type of elements maintained by this set

All Implemented Interfaces:
    Serializable, Cloneable, Iterable<E>, Collection<E>, NavigableSet<E>,
    Set<E>, SortedSet<E>

public class ConcurrentSkipListSet<E>
extends AbstractSet<E>
implements NavigableSet<E>, Cloneable, Serializable

A scalable concurrent NavigableSet implementation based on a
ConcurrentSkipListMap. The elements of the set are kept sorted according to
their natural ordering, or by a Comparator provided at set creation time,
depending on which constructor is used. 

-----------------------------------------------------------------------------
▼BlockingDequeの実装です
java.util.concurrent
Class LinkedBlockingDeque<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractQueue<E>
          extended by java.util.concurrent.LinkedBlockingDeque<E>

Type Parameters:
    E - the type of elements held in this collection

All Implemented Interfaces:
    Serializable, Iterable<E>, Collection<E>, BlockingDeque<E>,
    BlockingQueue<E>, Deque<E>, Queue<E>

public class LinkedBlockingDeque<E>
extends AbstractQueue<E>
implements BlockingDeque, Serializable

An optionally-bounded blocking deque based on linked nodes.

-----------------------------------------------------------------------------
▼タスクにデコレータパターンを適用します(タスクの修飾)
ScheduledThreadPoolExecutor.
decorateTask

protected <V> RunnableScheduledFuture<V> decorateTask(Runnable runnable,
                                          RunnableScheduledFuture<V> task)

    Modifies or replaces the task used to execute a runnable. This method
can be used to override the concrete class used for managing internal
tasks. The default implementation simply returns the given task.

    Parameters:
        runnable - the submitted Runnable
        task - the task created to execute the runnable 
    Returns:
        a task that can execute the runnable

............................................................
protected <V> RunnableScheduledFuture<V> decorateTask(Callable<V> callable,
                                           RunnableScheduledFuture<V> task)

    Modifies or replaces the task used to execute a callable. This method
can be used to override the concrete class used for managing internal
tasks. The default implementation simply returns the given task.

    Parameters:
        callable - the submitted Callable
        task - the task created to execute the callable 
    Returns:
        a task that can execute the callable

-----------------------------------------------------------------------------
▼スレッドプールのコアスレッドをkeep-aliveでタイムアウトします
ThreadPoolExecutor.
allowCoreThreadTimeOut

public void allowCoreThreadTimeOut(boolean value)

    Sets the policy governing whether core threads may time out and
terminate if no tasks arrive within the keep-alive time, being replaced if
needed when new tasks arrive. When false, core threads are never terminated
due to lack of incoming tasks. When true, the same keep-alive policy
applying to non-core threads applies also to core threads. To avoid
continual thread replacement, the keep-alive time must be greater than zero
when setting true. This method should in general be called before the pool
is actively used.

    Parameters:
        value - true if should time out, else false 
    Throws:
        IllegalArgumentException - if value is true and the current
keep-alive time is not greater than zero.

-----------------------------------------------------------------------------
ThreadPoolExecutor.
allowsCoreThreadTimeOut

public boolean allowsCoreThreadTimeOut()

    Returns true if this pool allows core threads to time out and terminate
if no tasks arrive within the keepAlive time, being replaced if needed when
new tasks arrive. When true, the same keep-alive policy applying to
non-core threads applies also to core threads. When false (the default),
core threads are never terminated due to lack of incoming tasks.

    Returns:
        true if core threads are allowed to time out, else false

-----------------------------------------------------------------------------
TimeUnit.
toMinutes
toHours
toDays

public long toMinutes(long duration)
public long toHours(long duration)
public long toDays(long duration)

-----------------------------------------------------------------------------
java.util.concurrent.atomic
AtomicBoolean.
lazySet

public final void lazySet(boolean newValue)

    Eventually sets to the given value.

    Parameters:
        newValue - the new value

............................................................
AtomicInteger.
lazySet

public final void lazySet(int newValue)

    Eventually sets to the given value.

    Parameters:
        newValue - the new value

............................................................
これらのクラスにもlazySet()メソッドがあります:
AtomicIntegerArray.
AtomicIntegerFieldUpdater.
AtomicLong.
AtomicLongArray.
AtomicLongFieldUpdater.
AtomicReference.
AtomicReferenceArray.
AtomicReferenceFieldUpdater.
lazySet 

-----------------------------------------------------------------------------
▼ロック〜シンクロナイザのオーナースレッドを設定します
java.util.concurrent.locks
Class AbstractOwnableSynchronizer

java.lang.Object
  extended by java.util.concurrent.locks.AbstractOwnableSynchronizer

All Implemented Interfaces:
    Serializable

Direct Known Subclasses:
    AbstractQueuedLongSynchronizer, AbstractQueuedSynchronizer

public abstract class AbstractOwnableSynchronizer
extends Object
implements Serializable

A synchronizer that may be exclusively owned by a thread. This class
provides a basis for creating locks and related synchronizers that may
entail a notion of ownership. The AbstractOwnableSynchronizer class itself
does not manage or use this information. However, subclasses and tools may
use appropriately maintained values to help control and monitor access and
provide diagnostics. 

...........................................................
Class AbstractQueuedLongSynchronizer 

A version of AbstractQueuedSynchronizer in which synchronization state is
maintained as a long. This class has exactly the same structure,
properties, and methods as AbstractQueuedSynchronizer with the exception
that all state-related parameters and results are defined as long rather
than int. This class may be useful when creating synchronizers such as
multilevel locks and barriers that require 64 bits of state.

-----------------------------------------------------------------------------
java.util.concurrent.locks.
LockSupport.
park(Object blocker) 
parkNanos(long nanos) 
parkNanos(Object blocker, long nanos)

-----------------------------------------------------------------------------
java.util.concurrent.locks
ReentrantReadWriteLock.
getReadHoldCount

public int getReadHoldCount()

    Queries the number of reentrant read holds on this lock by the current
thread. A reader thread has a hold on a lock for each lock action that is
not matched by an unlock action.

    Returns:
        the number of holds on the read lock by the current thread, or zero
if the read lock is not held by the current thread

-----------------------------------------------------------------------------
java.util.concurrent.locks
ReentrantReadWriteLock.WriteLock.
isHeldByCurrentThread

public boolean isHeldByCurrentThread()

    Queries if this write lock is held by the current thread. Identical in
effect to ReentrantReadWriteLock.isWriteLockedByCurrentThread().

    Returns:
        true if the current thread holds this lock and false otherwise

-----------------------------------------------------------------------------
java.util.concurrent.locks
ReentrantReadWriteLock.WriteLock.
getHoldCount

    Queries the number of holds on this write lock by the current thread. A
thread has a hold on a lock for each lock action that is not matched by an
unlock action. Identical in effect to
ReentrantReadWriteLock.getWriteHoldCount().

    Returns:
        the number of holds on this lock by the current thread, or zero if
this lock is not held by the current thread

-----------------------------------------------------------------------------