title: Java ServerSocket bound but not listening
body: <p>I have the following code for a keepalive serversocket, jdk 1.8, windows7 : </p>
  
  <pre><code>  serverSocket = new ServerSocket();
    serverSocket.setReuseAddress(true);
    serverSocket.bind(new InetSocketAddress(port)); // &lt;-- port is 19876
    System.out.println("Server bound on " + port + " " + serverSocket);
  </code></pre>
  
  <p>The problem is sometimes when I run this, it shows up listening in netstat, but sometimes it doesn't. Since there is no exception I'd expect it to be actually bound, but it's random.</p>
  
  <p>Correct operation, netstat just after the println: </p>
  
  <pre><code>  TCP    0.0.0.0:19876          0.0.0.0:0              LISTENING       7944
    TCP    [::]:19876             [::]:0                 LISTENING       7944
  </code></pre>
  
  <p>Netstat just after the println: </p>
  
  <pre><code>C:\Users\tmplr&gt;netstat -ano | find "198"
  
  C:\Users\tmplr&gt;netstat -ano | find "198"
  </code></pre>
  
  <p>In both cases there is no exception and the println produces the same : </p>
  
  <pre><code>Server bound on 19876 ServerSocket[addr=0.0.0.0/0.0.0.0,localport=19876]
  </code></pre>
  
  <p>Any idea what's wrong here or how could I debug the issue ? </p>