---
title: "jetty7 同时并发连接多个目的主机时(100+) 本地tcp端口不够用的解决方案,技术点滴,通讯+多线程"
author: "fuaotech"
date: "2015-07-17T12:45:44Z"
tags: []
categories: ["开源软件"]
slug: "jetty7-100-tcp"
draft: false
lastmod: "2015-09-24T23:53:30Z"
id: 2228152
url: "https://fuaotech.iteye.com/blog/2228152"
---

第一种方法

改注册表

改变这个变量：MaxUserPort可用端口数量由1024扩展为65535

改变这个变量:TcpTimedWaitDelay 把它缩短到30s 

 

 //先站个位置

```
public void startConnection( HttpDestination destination )
        throws IOException
    {
        SocketChannel channel = null;
        try
        {
            channel = SocketChannel.open();
            Address address = destination.isProxied() ? destination.getProxy() : destination.getAddress();
            channel.socket().setTcpNoDelay(true);
            channel.socket().setReuseAddress(true);
            channel.socket().setSoLinger(true, 0);
            if (_httpClient.isConnectBlocking())
            {
                channel.socket().connect(address.toSocketAddress(), _httpClient.getConnectTimeout());
                channel.configureBlocking(false);
                _selectorManager.register( channel, destination );
            }
            else
            {
                channel.configureBlocking(false);
                channel.connect(address.toSocketAddress());
                _selectorManager.register(channel,destination);
                ConnectTimeout connectTimeout = new ConnectTimeout(channel,destination);
                _httpClient.schedule(connectTimeout,_httpClient.getConnectTimeout());
                _connectingChannels.put(channel,connectTimeout);
            }
        }
```

 

 

 

[http://www.blogjava.net/yongboy/archive/2015/02/25/423037.html](http://www.blogjava.net/yongboy/archive/2015/02/25/423037.html)

[http://www.apihome.cn/api/java/Socket.html](http://www.apihome.cn/api/java/Socket.html)

[http://www.blogjava.net/yongboy/archive/2015/02/25/423037.html](http://www.blogjava.net/yongboy/archive/2015/02/25/423037.html)

[http://blog.csdn.net/zjl410091917/article/details/7990787](http://blog.csdn.net/zjl410091917/article/details/7990787)

[http://bbs.csdn.net/topics/390924834](http://bbs.csdn.net/topics/390924834)

[http://blog.csdn.net/feiyinzilgd/article/details/5894300](http://blog.csdn.net/feiyinzilgd/article/details/5894300)

[http://bbs.csdn.net/topics/390930935](http://bbs.csdn.net/topics/390930935)