1
| while(clientListener.waitingForResponse) { Thread.yield(); } |
This is completely unnecessary in any properly designed threading app. You should block on the response, which will pause the thread until the response is received. The thing that most closely maps to this is a Condition, but those are quite low-level, and judging by the context of the rest of the code around it, is probably an inappropriate primitive to use. You might be better served by using a BlockingQueue of Client objects that the listener enqueues.
Basically, you need to get familiar with the classes in java.util.concurrent and use
only those for your concurrency needs.