title: Java: how to compare object in different threads
body: <p>I have a server listening data from clients. Once a client sends data, it will go into a thread. Thus, each thread has a data. revFeaturePoints is the data which the server receives from clients.</p>
  
  <p>Each revFeaturePoints has a float array, I want to compute the Euclidean distance between different revFeaturePoints in different thread?</p>
  
  <p>I do not know how can let one thread to access another revFeaturePoints in other threads?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>public class MyServer {
  
  public static void main(String[] args) throws IOException{
      ServerSocket serverSocket = null;
  
      //bind a serverSocket to the port and listen
      try{
          serverSocket = new ServerSocket(8888);
          System.out.println("Listening: 8888");
      }catch(IOException e){
          e.printStackTrace();
      }
  
      while(true)
          new MyServerThread(serverSocket.accept()).start();
  }   
  }
  
  public class MyServerThread  extends Thread{
  //Create a socket for each client
  private Socket socket = null;
  private ObjectInputStream dataInputStream = null;
  private ObjectOutputStream dataOutputStream = null;
  private ArrayList&lt;FeaturePointList&gt; revFeaturePoints = null;
  
  //constructor
  public MyServerThread(Socket socket){
      super("MyServerThread");
      this.socket = socket;
  }
  
  @SuppressWarnings("unchecked")
  public void run(){
      try{            
          dataOutputStream = new ObjectOutputStream(socket.getOutputStream());
          dataInputStream = new ObjectInputStream(socket.getInputStream());
          System.out.println("ip: "+ socket.getInetAddress());
          revFeaturePoints = (ArrayList&lt;FeaturePointList&gt;) dataInputStream.readObject();          
  
      }catch(IOException e){
          e.printStackTrace();
      } catch (ClassNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } 
      finally{
          if(socket!=null){
              try{
                  socket.close();
              }catch(IOException e){
                  e.printStackTrace();
              }
          }
          if(dataInputStream!=null){
              try{
                  dataInputStream.close();
              }catch(IOException e){
                  e.printStackTrace();
              }               
          }
          if(dataOutputStream!=null){
              try{
                  dataOutputStream.close();
              }catch(IOException e){
                  e.printStackTrace();
              }               
          }
  
      }
  }
  </code></pre>
  
  <p>}</p>