Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java recommended way for shutting down multiple user sessions

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:

  1. Doing the loop with a maximum of 5 seconds delay for each session close procedure.

    OR

  2. 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.

like image 657
Gobliins Avatar asked May 09 '16 08:05

Gobliins


1 Answers

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.

like image 146
Warren Dew Avatar answered Oct 13 '22 14:10

Warren Dew