tomcat Standard IO中acceptCount究竟是神马?

tomcat最根本就是一个Socket Server,于是我找到了org.apache.tomcat.util.net.DefaultServerSocketFactory#createSocket(int port, int backlog),最终就是这个方法执行new java.net.ServerSocket(port, backlog)启动了一个ServerSocket实例。

查看ServerSocket API就发现@param backlog  the maximum length of the queue.

 

明确了,tomcat的acceptCount就是ServerSocket的等待队列。

 

但设置的acceptCount怎么设置到backlog上呢,我翻了好一会儿代码才注意到org.apache.catalina.connector.Connector中有一个变态的HashMap通过这个HashMap把参数名做了一次转换,再赋值给Http11Protocol使用。这样的变态我想应该是想方便tomcat的使用者吧,毕竟整一个backlog参数谁知道是干什么的,另外这个HashMap也把其它参数名做了转换,代码如下

	protected static HashMap replacements = new HashMap();
	static {
		replacements.put("acceptCount", "backlog");
		replacements.put("connectionLinger", "soLinger");
		replacements.put("connectionTimeout", "soTimeout");
		replacements.put("connectionUploadTimeout", "timeout");
		replacements.put("clientAuth", "clientauth");
		replacements.put("keystoreFile", "keystore");
		replacements.put("randomFile", "randomfile");
		replacements.put("rootFile", "rootfile");
		replacements.put("keystorePass", "keypass");
		replacements.put("keystoreType", "keytype");
		replacements.put("sslProtocol", "protocol");
		replacements.put("sslProtocols", "protocols");
	}

	// ------------------------------------------------------------- Properties

	/**
	 * Return a configured property.
	 */
	public Object getProperty(String name) {
		String repl = name;
		if (replacements.get(name) != null) {
			repl = (String) replacements.get(name);
		}
		return IntrospectionUtils.getProperty(protocolHandler, repl);
	}

	/**
	 * Set a configured property.
	 */
	public boolean setProperty(String name, String value) {
		String repl = name;
		if (replacements.get(name) != null) {
			repl = (String) replacements.get(name);
		}
		return IntrospectionUtils.setProperty(protocolHandler, repl, value);
	}
 

总结:acceptCount参数其实就是new java.net.ServerSocket(port, backlog)的第二个参数,了解后再设置就不会盲目了。

myblog

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值