42 |
|
* pool service incoming requests. It uses the preconfigured {@link |
43 |
|
* Executors#newFixedThreadPool} factory method: |
44 |
|
* |
45 |
< |
* <pre> |
45 |
> |
* <pre> {@code |
46 |
|
* class NetworkService implements Runnable { |
47 |
|
* private final ServerSocket serverSocket; |
48 |
|
* private final ExecutorService pool; |
70 |
|
* public void run() { |
71 |
|
* // read and service request on socket |
72 |
|
* } |
73 |
< |
* } |
74 |
< |
* </pre> |
73 |
> |
* }}</pre> |
74 |
|
* |
75 |
|
* The following method shuts down an <tt>ExecutorService</tt> in two phases, |
76 |
|
* first by calling <tt>shutdown</tt> to reject incoming tasks, and then |
77 |
|
* calling <tt>shutdownNow</tt>, if necessary, to cancel any lingering tasks: |
78 |
|
* |
79 |
< |
* <pre> |
79 |
> |
* <pre> {@code |
80 |
|
* void shutdownAndAwaitTermination(ExecutorService pool) { |
81 |
|
* pool.shutdown(); // Disable new tasks from being submitted |
82 |
|
* try { |
93 |
|
* // Preserve interrupt status |
94 |
|
* Thread.currentThread().interrupt(); |
95 |
|
* } |
96 |
< |
* } |
98 |
< |
* </pre> |
96 |
> |
* }}</pre> |
97 |
|
* |
98 |
|
* <p>Memory consistency effects: Actions in a thread prior to the |
99 |
|
* submission of a {@code Runnable} or {@code Callable} task to an |