backlog默认值为50
backlog原理
backlog影响的accept队列大小
客户端把数据放到accept队列,JVM再从accept队列取。
如果accept队列太小,JVM取数据不够快,那么accept队列就会溢出
源码找到ServerSocketChannel
无backlog参数,默认为0
public final ServerSocketChannel bind(SocketAddress local)
throws IOException
{
return bind(local, 0);
}
源码找到实现类ServerSocketChannelImpl,查看bind方法
Net.listen(this.fd, var2 < 1 ? 50 : var2); 此处代码,可以看出backlog默认值为< 1时,返回是50
public ServerSocketChannel bind(SocketAddress var1, int var2) throws IOException {
synchronized(this.lock) {
if (!this.isOpen()) {
throw new ClosedChannelException();
} else if (this.isBound()) {
throw new AlreadyBoundException();
} else {
InetSocketAddress var4 = var1 == null ? new InetSocketAddress(0) : Net.checkAddress(var1);
SecurityManager var5 = System.getSecurityManager();
if (var5 != null) {
var5.checkListen(var4.getPort());
}
NetHooks.beforeTcpBind(this.fd, var4.getAddress(), var4.getPort());
Net.bind(this.fd, var4.getAddress(), var4.getPort());
Net.listen(this.fd, var2 < 1 ? 50 : var2);
synchronized(this.stateLock) {
this.localAddress = Net.localAddress(this.fd);
}
return this;
}
}
}