Sample Usage. The following code sketch uses a copy-on-write set to maintain a set of Handler objects that perform some action upon state updates.
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 = ...; } public void update() { changeState(); for (Handler handler : handlers) handler.handle(); } }
This class is a member of the Java Collections Framework. @see CopyOnWriteArrayList @since 1.5 @author Doug Lea
Sample Usage. The following code sketch uses a copy-on-write set to maintain a set of Handler objects that perform some action upon state updates.
{@code}class Handler void handle(); ... } class X { private final CopyOnWriteArraySethandlers = new CopyOnWriteArraySet (); public void addHandler(Handler h) { handlers.add(h); } private long internalState; private synchronized void changeState() { internalState = ...; } public void update() { changeState(); for (Handler handler : handlers) handler.handle(); } }}
This class is a member of the Java Collections Framework. @see CopyOnWriteArrayList @since 1.5 @author Doug Lea @param < E> the type of elements held in this collection
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|