GC closes my ServerSocket

Weijun Wang weijun.wang at oracle.com
Wed Jun 13 01:38:52 PDT 2012


Hi All

I have a test that basically looks like:

     int p = new ServerSocket(0).getLocalPort();
     //....
     new Socket("localhost", p);

Recently it's failing on solaris-i586, and after some investigation, I 
realize that the ServerSocket object is GC'ed and auto-closed.

(But why only recently?)

So I change the first line to

     ServerSocket ss = new ServerSocket(0);
     int p = ss.getLocalPort();

and it's running fine.

I want to know if the ServerSocket object still has a chance to be 
closed. If yes, I'll add a

     ss.close();

at the end to be safer.

Thanks
Max



More information about the net-dev mailing list