multithreading - java recommended way for shutting down multiple user sessions -


we want disconnect our clients server.

so sent out messages sessions, include commands "close yourself"l

so in general this:

for (session session : sessions) {         closesession(session);         while(!verifyclosed(session)){             closesession(session);             retries++;             if(retries==10){                 retries = 0;                 break;             }         };     } 

now give seconds (let's 5) each session closed before doing sigterm kill methods.

so preferred way:

  1. doing loop maximum of 5 seconds delay each session close procedure.

    or

  2. start each session thread procedure sessions should closed @ same time.

    for (session session : sessions) {     startclosingthread(session); } 

update:

i notice users falsly hung on word "session", problem not sessionhandling @ all. if send closing message or disconnect socket not matter. not problem.

you replace word session userthread.

the problem need advice is: closing "userthread" take time, wait each thread closed , step next one, or start each userthread own repsonsible closing thread work on threads @ same time.

send session close request on sessions, wait 5 seconds, check sessions. way session closes can happen in parallel without starting whole bunch of new threads.


Comments