I'm trying to create a server app that calls out to another server to process info. I used the httpserver framework to get a http server interface (I'm using that for monitoring the server itself). I now need to have the server call another server with a simple socket connection.

But I cant find any good reference material for a server based off serverapplication that actually does client connections (that arent based off http at least) as well.

I have tried to do this by creating a new thread and passing a runnable that creates a new socket and tries to connect etc. But this causes problems because if I get an exception in the run() method, even if I catch them, they still get passed on to the Serverapplication error handler.

I also tried just running a socket connection in the main thread, which seems to work, but then I cant call waitForTerminationRequest because I'm already looping in the main thread. Which seems less than ideal.

So whats the preferred setup for a ServerApplication based server that creates outgoing sockets? Do you normally create a thread for the outgoing socket? if so, did I miss something in terms of the exception handling?