0

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?

Agrudge Amicus
  • 1,033
  • 7
  • 19
  • 1
    Why does closing the server socket necessarily terminate in-progress connections? That would seem to be a design choice. – Arfur Narf Apr 06 '23 at 01:27

0 Answers0