httpClient入门到精通-------连接池的关闭
来源:互联网 发布:赤峰市用友软件销售 编辑:程序博客网 时间:2024/05/29 19:34
官方给出的关闭方法
/* * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * */package cn.itcast.httpclient;import org.apache.http.conn.HttpClientConnectionManager;import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;public class ClientEvictExpiredConnections { public static void main(String[] args) throws Exception { PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); // 设置最大连接数 cm.setMaxTotal(200); // 设置每个主机地址的并发数 cm.setDefaultMaxPerRoute(20); new IdleConnectionEvictor(cm).start(); } public static class IdleConnectionEvictor extends Thread { private final HttpClientConnectionManager connMgr; private volatile boolean shutdown; public IdleConnectionEvictor(HttpClientConnectionManager connMgr) { this.connMgr = connMgr; } @Override public void run() { try { while (!shutdown) { synchronized (this) { wait(5000); // 关闭失效的连接 connMgr.closeExpiredConnections(); } } } catch (InterruptedException ex) { // 结束 } } public void shutdown() { shutdown = true; synchronized (this) { notifyAll(); } } }}
阅读全文
0 0
- httpClient入门到精通-------连接池的关闭
- httpClient入门到精通-------连接池
- httpClient入门到精通-------doGet
- httpClient入门到精通-------doPost
- httpClient入门到精通-------配置参数
- Java网络编程从入门到精通(27):关闭服务端连接
- Java网络编程从入门到精通(27):关闭服务端连接
- arcgis入门到精通视频教程下载连接
- HttpClient不能忽略的细节:关闭连接
- httpClient容易忽略的细节-关闭连接
- HttpClient容易忽视的细节-关闭连接
- .NET的入门到精通
- HttpClient关闭连接
- HttpClient的连接池
- Java网络编程从入门到精通(14):多种多样的建立网络连接的方式
- Java网络编程从入门到精通(14):多种多样的建立网络连接的方式
- Java网络编程从入门到精通(14):多种多样的建立网络连接的方式
- Java从入门到精通 - 数据库操作连接ACCESS数据库
- Encrypt-then-Mac
- mysql(5.7.17)字符集设置(character_set/collation)
- 《Spark SQL大数据实例开发》9.2 综合案例实战——电商网站搜索排名统计
- 让你看懂聚类分析
- web.xml 中的 servlet 和 servlet-mapping 标签
- httpClient入门到精通-------连接池的关闭
- kinect v2_bodyindex
- leetcode 525. Contiguous Array 统计1和0数量相等的最长子数组
- C++之cmath常用库函数一览
- 1136. A Delayed Palindrome (20)
- redis学习--下载、安装
- Tomcat中 HttpServletRequst的获取网页的几种方法比较
- 简单说一说Java的内存泄漏
- LINQ、反射和特性