We want to disconnect our clients from the server.
So we sent out some messages to the sessions, which include basically some commands like "close yourself"l
So in general I do something like this:
for (Session session : sessions) {
closeSession(session);
while(!verifyClosed(session)){
closeSession(session);
retries++;
if(retries==10){
retries = 0;
break;
}
};
}
Now I would like to give some seconds (let's say 5) for each session to get closed before doing some sigterm kill methods.
So what would be the preferred way:
Doing the loop with a maximum of 5 seconds delay for each session close procedure.
OR
Start for each session a thread that does this procedure so the sessions should be closed at the same time.
for (Session session : sessions) {
startClosingThread(session);
}
Update:
I notice that some users falsly hung up to much on the word "Session", the problem is not the SessionHandling at all. If i send a closing message or disconnect the Socket does not matter. This is not the problem.
You could replace the word Session with UserThread.
The problem for what i need some advice is: Closing a "UserThread" will take some time, so now wait for each thread to be closed and step to the next one, or start for each UserThread its own repsonsible Closing Thread to work on all Threads at the same time.
Send the session close request on all sessions, wait your five seconds, then check all sessions. That way the session closes can happen in parallel without starting a whole bunch of new threads.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With