title: Netty: send messages to all (TCP) clients from outside the pipeline
body: <p>I'm migrating my "plain NIO" (= I used the packages from the JDK directly) TCP server to Netty 4. </p>
  
  <p>I have threads that send messages to all clients, like health-checking packets, chat message broadcasts, direct chat messages to a single client, ... using a Collection of <code>SocketChannels</code> that I keep somewhere.</p>
  
  <p>How do I do that in Netty? Would it be wise to simply share a ChannelGroup between one of the Netty handlers and the threads that need to send messages? The channel would look like this:</p>
  
  <pre><code>public class ChannelCollectorHandler extends ChannelInboundMessageHandlerAdapter&lt;String&gt; {
  
      private static final ChannelGroup channels = new DefaultChannelGroup();
  
      public SecureChatServerHandler(ChannelGroup channels) {
         this.channels = channels;
      }
  
  
      @Override
      public void channelActive(final ChannelHandlerContext ctx) throws Exception {
          channels.add(ctx.channel());
      }
  
      ...
  }
  </code></pre>
  
  <p>in all the threads I would then simply do:</p>
  
  <pre><code>channels.write(...);
  </code></pre>
  
  <p>will that work?</p>