原帖,http://zhao3546.iteye.com/blog/246820
说是linux 1.5_03有问题,windows没问题.
例子代码: import java.io.IOException;
import java.net.Socket;
public class Main implements Runnable {
public static void main(String[] args) {
int threads = 500;
try {
threads = Integer.parseInt(args[0]);
} catch (Exception e) {
}
for (int i = 1; i <= threads; i++) {
new Thread(new Main()).start();
}
}
public void run() {
while (true) {
socketConnect();
}
}
public void socketConnect() {
Socket socket = null;
try {
socket = new Socket("127.0.0.1", 59998); // 请保证该端口59998没有Socket在监听。
} catch (IOException e) {
// e.printStackTrace();
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
// 不作处理
}
}
}
}
} 真的是jvmbug吗?那linuxjdk1.6还有该问题么?
说是linux 1.5_03有问题,windows没问题.
例子代码: import java.io.IOException;
import java.net.Socket;
public class Main implements Runnable {
public static void main(String[] args) {
int threads = 500;
try {
threads = Integer.parseInt(args[0]);
} catch (Exception e) {
}
for (int i = 1; i <= threads; i++) {
new Thread(new Main()).start();
}
}
public void run() {
while (true) {
socketConnect();
}
}
public void socketConnect() {
Socket socket = null;
try {
socket = new Socket("127.0.0.1", 59998); // 请保证该端口59998没有Socket在监听。
} catch (IOException e) {
// e.printStackTrace();
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
// 不作处理
}
}
}
}
} 真的是jvmbug吗?那linuxjdk1.6还有该问题么?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货