public void registerSessionThread(SessionThread newSession){
synchronized (this) {
    List<SessionThread> toBeRemoved=new ArrayList<SessionThread>();
    for (    SessionThread sessionThread : sessionThreads) {
      if (!sessionThread.isAlive()) {
        Log.d(TAG,"Cleaning up finished session...");
        try {
          sessionThread.join();
          Log.d(TAG,"Thread joined");
          toBeRemoved.add(sessionThread);
          sessionThread.closeSocket();
        }
 catch (        InterruptedException e) {
          Log.d(TAG,"Interrupted while joining");
        }
      }
    }
    for (    SessionThread removeThread : toBeRemoved) {
      sessionThreads.remove(removeThread);
    }
    sessionThreads.add(newSession);
  }
  Log.d(TAG,"Registered session thread");
}

public void registerSessionThread ( SessionThread newSession ) { synchronized ( this ) { List < SessionThread > toBeRemoved = new ArrayList < SessionThread > ( ) ; for ( SessionThread sessionThread : sessionThreads ) { if ( ! sessionThread . isAlive ( ) ) { Log . d ( TAG , "Cleaning up finished session..." ) ; try { sessionThread . join ( ) ; Log . d ( TAG , "Thread joined" ) ; toBeRemoved . add ( sessionThread ) ; sessionThread . closeSocket ( ) ; } catch ( InterruptedException e ) { Log . d ( TAG , "Interrupted while joining" ) ; } } } for ( SessionThread removeThread : toBeRemoved ) { sessionThreads . remove ( removeThread ) ; } sessionThreads . add ( newSession ) ; } Log . d ( TAG , "Registered session thread" ) ; }
the ftpserverservice must know about all running session threads so they can be terminated on exit . called when a new session is created .
