src/share/classes/java/util/concurrent/CopyOnWriteArraySet.java

Print this page

        

*** 57,72 **** * * <p> <b>Sample Usage.</b> The following code sketch uses a * copy-on-write set to maintain a set of Handler objects that * perform some action upon state updates. * ! * <pre> * class Handler { void handle(); ... } * * class X { ! * private final CopyOnWriteArraySet&lt;Handler&gt; handlers ! * = new CopyOnWriteArraySet&lt;Handler&gt;(); * public void addHandler(Handler h) { handlers.add(h); } * * private long internalState; * private synchronized void changeState() { internalState = ...; } * --- 57,72 ---- * * <p> <b>Sample Usage.</b> The following code sketch uses a * copy-on-write set to maintain a set of Handler objects that * perform some action upon state updates. * ! * <pre> {@code * class Handler { void handle(); ... } * * class X { ! * private final CopyOnWriteArraySet<Handler> handlers ! * = new CopyOnWriteArraySet<Handler>(); * public void addHandler(Handler h) { handlers.add(h); } * * private long internalState; * private synchronized void changeState() { internalState = ...; } *
*** 73,84 **** * public void update() { * changeState(); * for (Handler handler : handlers) * handler.handle(); * } ! * } ! * </pre> * * <p>This class is a member of the * <a href="{@docRoot}/../technotes/guides/collections/index.html"> * Java Collections Framework</a>. * --- 73,83 ---- * public void update() { * changeState(); * for (Handler handler : handlers) * handler.handle(); * } ! * }}</pre> * * <p>This class is a member of the * <a href="{@docRoot}/../technotes/guides/collections/index.html"> * Java Collections Framework</a>. *