Depending on how high-volume your traffic is, you might look at NIO, though it's a significantly more complicated option to understand and employ.
If you have just a basic application, then start a thread that just blocks on receive(packet)
. Whenever it returns (a packet has arrived), dispatch the packet to some sort of handler. If there's low traffic, this might be a BlockingQueue
that some other thread is listening to; if you have high traffic, you might send a job to an ExecutorService
to be handled in parallel.