I have the following snippet of codes first each of the thread is a socket waitign for connection where its gets a connection does all he necessary. Thereafter another section in the run it does this //run a new db connection and does a select where all those have not been updated will be send to webservice and later update their status. The weird part I notice at times this section is ran twice? Could it be the previous thread was not closed?

 public void run() {

 try{
      //socket connection codes which does all the necessary and finally close the connection.
 }
          catch (SocketTimeoutException ex)  
          { 
               System.out.println("SocketTimeoutException has been caught in in the main first try");
               ex.printStackTrace();
          }  
          catch (IOException ex)  
          { 
               System.out.println("IOException has been caught in in the main first try");
               ex.printStackTrace();
          }  
          catch (Exception ex)  
          { 
               System.out.println( receivedSocketConn1.getInetAddress() +":"+receivedSocketConn1.getPort()+" IS CONNECTED ");

               System.out.println("MyError:Exception has been caught in in the main first try");
               ex.printStackTrace(System.out);
          }   

   //run a new db connection and does a select where all those have not been updated will be send to webservice and later update their status.

   }

Edited 1 Year Ago by pritaeas: Moved.

Without access to the rest of your code I can only say that yes, you could be dealing with a thread race condition here. You might want to consider using a mutex that will keep a second thread from starting if the previous one has not yet terminated.

Edited 1 Year Ago by rubberman

This article has been dead for over six months. Start a new discussion instead.