18 |
|
* and receives its partner's object on return. |
19 |
|
* |
20 |
|
* <p><b>Sample Usage:</b> |
21 |
< |
* Here are the highlights of a class that uses an <tt>Exchanger</tt> to |
22 |
< |
* swap buffers between threads so that the thread filling the |
23 |
< |
* buffer gets a freshly |
24 |
< |
* emptied one when it needs it, handing off the filled one to |
25 |
< |
* the thread emptying the buffer. |
26 |
< |
* <pre> |
21 |
> |
* Here are the highlights of a class that uses an {@code Exchanger} |
22 |
> |
* to swap buffers between threads so that the thread filling the |
23 |
> |
* buffer gets a freshly emptied one when it needs it, handing off the |
24 |
> |
* filled one to the thread emptying the buffer. |
25 |
> |
* <pre>{@code |
26 |
|
* class FillAndEmpty { |
27 |
< |
* Exchanger<DataBuffer> exchanger = new Exchanger(); |
27 |
> |
* Exchanger<DataBuffer> exchanger = new Exchanger<DataBuffer>(); |
28 |
|
* DataBuffer initialEmptyBuffer = ... a made-up type |
29 |
|
* DataBuffer initialFullBuffer = ... |
30 |
|
* |
59 |
|
* new Thread(new EmptyingLoop()).start(); |
60 |
|
* } |
61 |
|
* } |
62 |
< |
* </pre> |
62 |
> |
* }</pre> |
63 |
|
* |
64 |
|
* <p>Memory consistency effects: For each pair of threads that |
65 |
|
* successfully exchange objects via an {@code Exchanger}, actions |