开发者

will ServerSocket(port) and multiple threading works well for 5000 simultaneous clients hits?

I am working with the serversocket class and opening threads when 开发者_JAVA技巧a new client hits the serversocket:

serverSocket = new ServerSocket(port);

while (true) {
        Socket clientSocket = serverSocket.accept();
        new Thread(this).start();//opening multiple threads
}

but when 5000 clients hits on this serversocket an error shows up on the client side: java.net.ConnectException: Connection refused: connect

Please tell me what is the better way to open a serversocket so that it can accept all the client connections? there is a 1 millisecond time gap between simultaneous client connections.


There are 2 things you should be checking out definately.

File descriptor limit. On a Linux based system, you can check that using ulimit.

Secondly, Serversockets have waiting queue size, if you have more connections waiting than queue size, they will be refused immediately. You should try ServerSocket(port, backlog) constructor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜