Okay, I think you can solve the thread creation problem by passing a thread count to your EventLoopGroup constructors. Try this to start, and increase the number only when you've
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup(2);
(yes, that's crazy conservative, and yes, that's where you should start).
Now, about the rest of the code: wildloop() does not do what you think it does, and will have all sorts of problems:
1. There's no guarantee that you will process a message from a client before the next one comes and clobbers the previous one - you're going to lose data.
2. For another thing, the field "stringbuffer" is not marked volatile, and there's nothing to make it thread-safe, but it's being written on one thread and read on another, and there's nothing to stop it being overwritten before it has been received. That is not a workable way to pass messages between threads (see below for something that will work).
3. You're keeping a pool of DiscardServerHandler instances (and really you should have exactly one), but there's no guarantee I can see that you won't use one that's already been used by a different client, and wind up reading a message from some other client as coming from the one it's now used with
Here's a rough sketch of how this should work:
- Create your DiscardServerHandler in its field definition - there will be exactly one (I think you need to annotate it with @Shareable?). Use the same handler for all requests. And don't have any state - any fields you set when processing a message in that class.
- If you can, process messages from clients where they are, as they come in - don't have a separate loop at all. To distribute data to other clients, do something like the code I posted earlier; probably using the second technique.
- If you
can't process messages from clients as they come in, do have a separate loop, on a separate thread (or the main thread, whatever). But use a
thread-safe queue - have the handler throw the message into the queue, and have that loop just loop polling queue.take() and sending on whatever it has. ConcurrentLinkedQueue would be a good starting place -
http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentLinkedQueue.html
The main thing to keep in mind writing something like this is, anything that is going to be accessed by more than one thread needs special treatment - like using a Queue. Things like the JDK's *Queue classes are very useful because they take care of a lot of the hard parts of that for you. In particular, since not all tutorials mention it - if you're going to set a field on object X from thread A, and read that field it from thread B, you must either mark it as volatile or use synchronization, unless it is a final field set when the object is being constructed.
Take a look at some concurrency tutorials - they will help:
Best of luck,
-Tim