I have created an EchoServer extending Thread. I want it to be possible to shut down the server so I have the following in my code when overriding Thread's run():
and in a shutDown method:
Problem is this can throw IOException in run() because shutDown can be executed the condition in the while loop in run has been checked. If I synchronize on the EchoServer itself I lose all concurrency. What are possible strategies ?
Unrelated: I am assuming there is no direct way of getting references to all Sockets coming from a specific ServerSocket's accept, correct ?
Joined: Jan 12, 2010
OK. Thinking about it I think I am suffering from Threadatitis ! That EchoServer probably should not be a thread.
So will use synchronization on some state variable isAlive probably and double check somehow. Sounds better, right ?
Double Checked locking works from Java 1.5 on, but is it considered bad to use ?