【发布时间】:2011-12-29 04:08:23
【问题描述】:
以下代码可以重现该问题: int errAt = -1;
try {
System.out.println("start...");
for (int i = 0; i < 4000; i++) {
errAt = i;
DatagramSocket result = new DatagramSocket(null);
result.bind(new InetSocketAddress(InetAddress.getLocalHost(), 9005));
result.close();
//System.out.println(i);
}
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
System.out.println("ErrAt: " + errAt);
e.printStackTrace();
} finally {
System.out.println("end...");
}
在我的电脑上,运行 2k+ 次后,我会看到“java.net.BindException:地址已在使用:无法绑定”异常。
我不确定,这是否意味着close方法没有立即关闭本机套接字?
【问题讨论】: