Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

process unterminated under Linux Fedora Core

Gadar Soe
2005-06-21
2013-04-09
  • Gadar Soe
    Gadar Soe
    2005-06-21

    Hi,

    I tried to run NFC chat server as Tomcat embedded servelet under Fedora Core Linux. After I shutdown Tomcat, I still see the process is still running and the chat server port is still open. When I disable the NFC module, Tomcat terminates as expected.The Tomcat version I am using is 4.1.31 and OS is Fedora Core 3. What could be the problem? Has any of you encountered this problem? Any suggestion is welcome.

     
    • Daniel Tahin
      Daniel Tahin
      2005-08-10

      Hi!

      There are 2 way to solve this:
      1: simply close the _socketServer in ChatServer.java. Since this simply closes the socket, no other clean-up can be done.

      2: since _socketServer.accept() in ChatServer is waiting for incomming connections, we interrupt it, and we can do clean-up. To do so, open a socket connection
          from the Servlet to the port NFC-server is listening on, and send the command "/stat".

      1: add this code to ChatServer.java
          public void pleaseStop() {
              _keepGoing = false;
              try {
              _serverSocket.close();
              }
              catch (Exception ex) {
                System.out.println("-------------------------");
                System.out.println("serverSocket.close():");
                ex.printStackTrace();
                System.out.println("-------------------------");
              }
          }

      2: ChatServer.java
         protected void acceptConnections() {

            ...

            cleanUp();
         }

         private void cleanUp() {
          System.out.println("Doing cleanup:");
         
          System.out.println("    logging off the Clients!");
          //this could take a while, if we have more 100 users??
          Object _cl[] = _vulture.getClients();
          for(int a=0; a<_cl.length; a++) {
              signOff( (ChatClient)_cl[a] );
          }
         
          System.out.println("    shutting down Dispatcher!");
          _dispatcher.pleaseStop();
         
          System.out.println("    shutting down Vulture!");
          _vulture.pleaseStop();
          _vulture.interrupt();
          //inform the other servers via JMS, that this server is died?

          try{   
              _serverSocket.close();
          }catch(Exception e) {
              System.err.println("ChatServer: can't close server socket!");
              _serverSocket = null;
          }
            }

            Dispatcher.java
            public void queue(Message m) {
          //*** for cleanup. If pleaseStop() was called, we don't accept new messages!
          if(_keepGoing==false) {
              return;
          }

              ....

            }

            TunnelServlet.java
            public void pleaseStop() {
              ...

                 //*** opening a socket connection to the local ChatServer,
          //to "interrupt" it (see acceptConnections()@ChatServer)
          //giving /stats will cause the chatserver, to create a new
          //socket and doing something...
          try{
              Socket s = new Socket("localhost", _chatServer.getPort());
              PrintStream out = new PrintStream(s.getOutputStream());
              out.println("/stats");
              out.flush();
              out.close();
              s.close();
          }catch(Exception e) {}
            }

            public void destroy() {
              ...

              System.err.println("Forcefully killing the accept thread.");
                      //*** _runner.stop();
      //do not invoke this! Invoke pleaseStop()
              // instead to make some cleanups in the ChatServer!
                  }
                 pleaseStop();

              ...
            }

           Vulture.java
           //*** used by cleanUp()@ChatServer
          public Object[] getClients() {
          synchronized(_clients) {
              return _clients.toArray();
          }
          }