While making an attempt to shut-down a server, the server must be waiting (via accept()
method) for new threads to make connection. My question is same as the question posted here:
How can I interrupt a ServerSocket accept() method?
But I have few other questions/reservations about the offered solutions:
1: In case I use close()
then it will close the server socket and eventually the client threads who are still in execution - they will be brought down. This is something I want to avoid in order to cleanly shutdown the server (let every thread complete and no new client thread/connection to be made).
2: In case I use some kind of time-out for the accept()
- what if the time-out happens, the control flow marches ahead and before the control flow can again reaches accept()
, some client attempts for a new connection?