title: Two thread shared static variable
body: <p>I want to run a simple server-client program where clients checks each 5 sec best server and connect always best server. So I wrote following code but I get stackoverflow error.</p>
  
  <pre><code>public static void main(String[] args) throws IOException, InterruptedException {
          RTT best = null;
          BestServer bestserver = new BestServer(best);
  
          Socket clientSocket = new Socket(bestserver.bestserver.ip, 6789);
          System.out.println("I connect best server");
  }   
  
  public class BestServer implements Runnable{
  
      static RTT bestserver;
  
      public BestServer(RTT best) throws InterruptedException{
          bestserver = best;
          findBest();
      }
  
      public static void findBest() throws InterruptedException{
  
          Thread t = new Thread(new BestServer(bestserver));
          t.start();
          t.sleep(5000);
  }
  
  public void run(){
      //..
  }
  </code></pre>