开发者

how can I determine the maximum value of 'backlog' that is allowed on the current system?

I'm playing with ServerSocket and I don't see / find what the limit of the backlog is. The docs don't say anything about this:

http://download.oracle.com/javase/6/docs/api/java/net/ServerSocket.html#ServerSocket(int, int)

My code is like this:

serverSocket = ServerSocketChannel.open();
serverSocket.socket().bind(null, 10000);

but I assume that 10000 might be too much if a sy开发者_如何学运维stem doesn't have enough RAM. So is there a way to determine the maximum value for backlog that I can use?

It seems like in c++ you can use SOMAXCONN - does something similar exist for Java?


If there were, it would be system dependent: for Windows

The backlog parameter is limited (silently) to a reasonable value as determined by the underlying service provider. Illegal values are replaced by the nearest legal value. There is no standard provision to find out the actual backlog value.

Linux states it a little differently but you would need to go through the sysctl interface (or possibly /proc).

In any case, it would appear you would need to execute some system specific code.

I believe most implementations will just use their maximum value if the specified value is "too big" so this may not be a concern for your application?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜