52 * <li>It is best suited for applications in which set sizes generally
53 * stay small, read-only operations
54 * vastly outnumber mutative operations, and you need
55 * to prevent interference among threads during traversal.
56 * <li>It is thread-safe.
57 * <li>Mutative operations ({@code add}, {@code set}, {@code remove}, etc.)
58 * are expensive since they usually entail copying the entire underlying
59 * array.
60 * <li>Iterators do not support the mutative {@code remove} operation.
61 * <li>Traversal via iterators is fast and cannot encounter
62 * interference from other threads. Iterators rely on
63 * unchanging snapshots of the array at the time the iterators were
64 * constructed.
65 * </ul>
66 *
67 * <p><b>Sample Usage.</b> The following code sketch uses a
68 * copy-on-write set to maintain a set of Handler objects that
69 * perform some action upon state updates.
70 *
71 * <pre> {@code
72 * class Handler { void handle(); ... }
73 *
74 * class X {
75 * private final CopyOnWriteArraySet<Handler> handlers
76 * = new CopyOnWriteArraySet<>();
77 * public void addHandler(Handler h) { handlers.add(h); }
78 *
79 * private long internalState;
80 * private synchronized void changeState() { internalState = ...; }
81 *
82 * public void update() {
83 * changeState();
84 * for (Handler handler : handlers)
85 * handler.handle();
86 * }
87 * }}</pre>
88 *
89 * <p>This class is a member of the
90 * <a href="{@docRoot}/java.base/java/util/package-summary.html#CollectionsFramework">
91 * Java Collections Framework</a>.
92 *
|
52 * <li>It is best suited for applications in which set sizes generally
53 * stay small, read-only operations
54 * vastly outnumber mutative operations, and you need
55 * to prevent interference among threads during traversal.
56 * <li>It is thread-safe.
57 * <li>Mutative operations ({@code add}, {@code set}, {@code remove}, etc.)
58 * are expensive since they usually entail copying the entire underlying
59 * array.
60 * <li>Iterators do not support the mutative {@code remove} operation.
61 * <li>Traversal via iterators is fast and cannot encounter
62 * interference from other threads. Iterators rely on
63 * unchanging snapshots of the array at the time the iterators were
64 * constructed.
65 * </ul>
66 *
67 * <p><b>Sample Usage.</b> The following code sketch uses a
68 * copy-on-write set to maintain a set of Handler objects that
69 * perform some action upon state updates.
70 *
71 * <pre> {@code
72 * class Handler { void handle() { ... } }
73 *
74 * class X {
75 * private final CopyOnWriteArraySet<Handler> handlers
76 * = new CopyOnWriteArraySet<>();
77 * public void addHandler(Handler h) { handlers.add(h); }
78 *
79 * private long internalState;
80 * private synchronized void changeState() { internalState = ...; }
81 *
82 * public void update() {
83 * changeState();
84 * for (Handler handler : handlers)
85 * handler.handle();
86 * }
87 * }}</pre>
88 *
89 * <p>This class is a member of the
90 * <a href="{@docRoot}/java.base/java/util/package-summary.html#CollectionsFramework">
91 * Java Collections Framework</a>.
92 *
|