16 |
|
|
17 |
|
{@link java.util.concurrent.Executor} is a simple standardized |
18 |
|
interface for defining custom thread-like subsystems, including thread |
19 |
< |
pools, asynchronous IO, and lightweight task frameworks. Depending on which |
20 |
< |
concrete Executor class is being used, tasks may execute in a newly |
21 |
< |
created thread, an existing task-execution thread, or the thread |
19 |
> |
pools, asynchronous IO, and lightweight task frameworks. Depending on |
20 |
> |
which concrete Executor class is being used, tasks may execute in a |
21 |
> |
newly created thread, an existing task-execution thread, or the thread |
22 |
|
calling <tt>execute()</tt>, and may execute sequentially or |
23 |
< |
concurrently. Executors also standardize ways of calling threads that |
24 |
< |
compute functions returning results, via a {@link |
25 |
< |
java.util.concurrent.Future}. This is supported in part by defining |
26 |
< |
interface {@link java.util.concurrent.Callable}, the argument/result |
27 |
< |
analog of Runnable. |
23 |
> |
concurrently. |
24 |
|
|
25 |
|
<p> {@link java.util.concurrent.ExecutorService} provides a more |
26 |
|
complete framework for executing Runnables. An ExecutorService |
29 |
|
{@link java.util.concurrent.ThreadPoolExecutor}, a tunable and |
30 |
|
flexible thread pool and {@link |
31 |
|
java.util.concurrent.ScheduledExecutor}, which adds support for |
32 |
< |
delayed and periodic task execution. These, and other Executors can |
33 |
< |
be used in conjunction with a {@link |
34 |
< |
java.util.concurrent.CancellableTask} or {@link |
35 |
< |
java.util.concurrent.FutureTask} to asynchronously start a potentially |
36 |
< |
long-running computation and query to determine if its execution has |
37 |
< |
completed, or cancel it. |
38 |
< |
|
39 |
< |
<p> The {@link java.util.concurrent.Executors} class provides factory |
40 |
< |
methods for the most common kinds and configurations of Executors, as |
41 |
< |
well as a few utility methods for using them. |
32 |
> |
delayed and periodic task execution. The {@link |
33 |
> |
java.util.concurrent.Executors} class provides factory methods for the |
34 |
> |
most common kinds and configurations of Executors, as well as a few |
35 |
> |
utility methods for using them. |
36 |
> |
|
37 |
> |
<p> Executors may be used with threads that compute functions |
38 |
> |
returning results. A {@link java.util.concurrent.Future} returns the |
39 |
> |
results of a {@link java.util.concurrent.Callable}, the result-bearing |
40 |
> |
analog of {@link java.lang.Runnable}. Instances of concrete class |
41 |
> |
{@link java.util.concurrent.FutureTask} may be submitted to Executors |
42 |
> |
to asynchronously start a potentially long-running computation, query |
43 |
> |
to determine if its execution has completed, or cancel it. The {@link |
44 |
> |
java.util.concurrent.CancellableTask} class provides similar control |
45 |
> |
for actions that do not bear results. |
46 |
|
|
47 |
|
<h2>Queues</h2> |
48 |
|
|
65 |
|
|
66 |
|
The {@link java.util.concurrent.TimeUnit} class provides multiple |
67 |
|
granularities (including nanoseconds) for specifying and controlling |
68 |
< |
time-out based operations. Nearly all other classes in the package |
69 |
< |
contain operations based on time-outs in addition to indefinite waits. |
70 |
< |
In all cases that time-outs are used, the time-out specifies the |
71 |
< |
minimum time that the method should wait before indicating that it |
72 |
< |
timed-out. The virtual machine should make a "best effort" |
73 |
< |
to detect time-outs as soon as possible after they occur. Regardless |
74 |
< |
of the efforts of the virtual machine, the normal scheduling |
75 |
< |
mechanisms, and the need to re-acquire locks in many cases, can lead |
76 |
< |
to an indefinite amount of time elapsing between a time-out being |
77 |
< |
detected and a thread actually executing again after that time-out. |
68 |
> |
time-out based operations. Most classes in the package contain |
69 |
> |
operations based on time-outs in addition to indefinite waits. In all |
70 |
> |
cases that time-outs are used, the time-out specifies the minimum time |
71 |
> |
that the method should wait before indicating that it |
72 |
> |
timed-out. Implementations make a "best effort" to detect |
73 |
> |
time-outs as soon as possible after they occur. However, an indefinite |
74 |
> |
amount of time may elapse between a time-out being detected and a |
75 |
> |
thread actually executing again after that time-out. |
76 |
|
|
77 |
|
<h2>Synchronizers</h2> |
78 |
|
|
102 |
|
"concurrent". A concurrent collection is thread-safe, but not |
103 |
|
governed by a single exclusion lock. In the particular case of |
104 |
|
ConcurrentHashMap, it safely permits any number of concurrent reads as |
105 |
< |
well as a tunable number of concurrent writes. There may still be a |
106 |
< |
role for "synchronized" classes in some multithreaded programs -- they |
107 |
< |
can sometimes be useful when you need to prevent all access to a |
108 |
< |
collection via a single lock, at the expense of much poorer |
109 |
< |
scalability. In all other cases, "concurrent" versions are normally |
110 |
< |
preferable. |
105 |
> |
well as a tunable number of concurrent writes. "Synchronized" classes |
106 |
> |
can be useful when you need to prevent all access to a collection via |
107 |
> |
a single lock, at the expense of poorer scalability. In other cases in |
108 |
> |
which multiple threads are expected to access a common collection, |
109 |
> |
"concurrent" versions are normally preferable. And unsynchronized |
110 |
> |
collections are preferable when either collections are unshared, or |
111 |
> |
are accessible only when holding other locks. |
112 |
|
|
113 |
|
<p> Most concurrent Collection implementations (including most Queues) |
114 |
|
also differ from the usual java.util conventions in that their Iterators |