Code example for CopyOnWriteArraySet

    private static final long serialVersionUID = 1L;
    private static final String GUEST_PREFIX = "Guest";
    private final AtomicInteger connectionIds = new AtomicInteger(0);
    private final Set<ChatMessageInbound> connections =
            new CopyOnWriteArraySet<ChatMessageInbound>();
    protected StreamInbound createWebSocketInbound(String subProtocol,
            HttpServletRequest request) {
        return new ChatMessageInbound(connectionIds.incrementAndGet());
    private final class ChatMessageInbound extends MessageInbound { 
        private final String nickname;
        private ChatMessageInbound(int id) {
Connect your IDE to all the code out there  Get Codota for Java