当前位置: 首页>>代码示例>>Java>>正文


Java ConnManagerParams.setMaxTotalConnections方法代码示例

本文整理汇总了Java中org.apache.http.conn.params.ConnManagerParams.setMaxTotalConnections方法的典型用法代码示例。如果您正苦于以下问题:Java ConnManagerParams.setMaxTotalConnections方法的具体用法?Java ConnManagerParams.setMaxTotalConnections怎么用?Java ConnManagerParams.setMaxTotalConnections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.conn.params.ConnManagerParams的用法示例。


在下文中一共展示了ConnManagerParams.setMaxTotalConnections方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import org.apache.http.conn.params.ConnManagerParams; //导入方法依赖的package包/类
public static HttpClient get() {
    HttpParams httpParams = new BasicHttpParams();
    ConnManagerParams.setTimeout(httpParams, 3000);
    ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(30));
    ConnManagerParams.setMaxTotalConnections(httpParams, 30);
    HttpClientParams.setRedirecting(httpParams, true);
    HttpProtocolParams.setUseExpectContinue(httpParams, true);
    HttpConnectionParams.setStaleCheckingEnabled(httpParams, false);
    HttpConnectionParams.setSoTimeout(httpParams, 2000);
    HttpConnectionParams.setConnectionTimeout(httpParams, 2000);
    HttpConnectionParams.setTcpNoDelay(httpParams, true);
    HttpConnectionParams.setSocketBufferSize(httpParams, 8192);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTP_TAG, PlainSocketFactory.getSocketFactory(), 80));
    try {
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);
        SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        schemeRegistry.register(new Scheme(IDataSource.SCHEME_HTTPS_TAG, sf, 443));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return new DefaultHttpClient(new ThreadSafeClientConnManager(httpParams, schemeRegistry), httpParams);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:26,代码来源:PoolingClientConnectionManager.java

示例2: a

import org.apache.http.conn.params.ConnManagerParams; //导入方法依赖的package包/类
public static b a(String str) {
    HttpParams basicHttpParams = new BasicHttpParams();
    HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);
    HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, false);
    HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
    HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
    HttpConnectionParams.setSocketBufferSize(basicHttpParams, 8192);
    HttpClientParams.setRedirecting(basicHttpParams, true);
    HttpClientParams.setAuthenticating(basicHttpParams, false);
    HttpProtocolParams.setUserAgent(basicHttpParams, str);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme(com.alipay.sdk.cons.b.a, SSLCertificateSocketFactory.getHttpSocketFactory(30000, null), WebSocket.DEFAULT_WSS_PORT));
    ClientConnectionManager threadSafeClientConnManager = new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry);
    ConnManagerParams.setTimeout(basicHttpParams, 60000);
    ConnManagerParams.setMaxConnectionsPerRoute(basicHttpParams, new ConnPerRouteBean(10));
    ConnManagerParams.setMaxTotalConnections(basicHttpParams, 50);
    Security.setProperty("networkaddress.cache.ttl", "-1");
    HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
    return new b(threadSafeClientConnManager, basicHttpParams);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:b.java

示例3: createHttpParams

import org.apache.http.conn.params.ConnManagerParams; //导入方法依赖的package包/类
private HttpParams createHttpParams() {
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF-8");
    HttpProtocolParams.setUseExpectContinue(params, false);
    ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(3));
    ConnManagerParams.setMaxTotalConnections(params, 3);
    ConnManagerParams.setTimeout(params, 1000);
    HttpConnectionParams.setConnectionTimeout(params, 30000);
    HttpConnectionParams.setSoTimeout(params, 30000);
    HttpConnectionParams.setStaleCheckingEnabled(params, false);
    HttpConnectionParams.setTcpNoDelay(params, true);
    HttpConnectionParams.setSocketBufferSize(params, 8192);
    HttpClientParams.setRedirecting(params, false);
    return params;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:17,代码来源:HttpEngine.java

示例4: getInstance

import org.apache.http.conn.params.ConnManagerParams; //导入方法依赖的package包/类
/**
 * Returns the one <code>WebServiceUtil</code> instance
 * @return the one <code>WebServiceUtil</code> instance
 */
public static WebServiceUtil getInstance() {
  // This needs to be here instead of in the constructor because
  // it uses classes that are in the AndroidSDK and thus would
  // cause Stub! errors when running the component descriptor.
  synchronized(httpClientSynchronizer) {
    if (httpClient == null) {
      SchemeRegistry schemeRegistry = new SchemeRegistry();
      schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
      schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
      BasicHttpParams params = new BasicHttpParams();
      HttpConnectionParams.setConnectionTimeout(params, 20 * 1000);
      HttpConnectionParams.setSoTimeout(params, 20 * 1000);
      ConnManagerParams.setMaxTotalConnections(params, 20);
      ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params,
          schemeRegistry);
      WebServiceUtil.httpClient = new DefaultHttpClient(manager, params);
    }
  }
  return INSTANCE;
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:25,代码来源:WebServiceUtil.java

示例5: createHttpClient

import org.apache.http.conn.params.ConnManagerParams; //导入方法依赖的package包/类
private DefaultHttpClient createHttpClient() {
	HttpParams params = new BasicHttpParams();
	HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
	HttpProtocolParams.setContentCharset(params,
			HTTP.DEFAULT_CONTENT_CHARSET);
	HttpProtocolParams.setUseExpectContinue(params, true);
	HttpConnectionParams.setConnectionTimeout(params,
			CONNETED_TIMEOUT * 1000);
	HttpConnectionParams.setSoTimeout(params, CONNETED_TIMEOUT * 1000);
	HttpConnectionParams.setSocketBufferSize(params, 8192);
	ConnManagerParams.setMaxTotalConnections(params, 4);
	SchemeRegistry schReg = new SchemeRegistry();
	schReg.register(new Scheme("http", PlainSocketFactory
			.getSocketFactory(), 80));
	schReg.register(new Scheme("https",
			SSLSocketFactory.getSocketFactory(), 443));

	ClientConnectionManager connMgr = new ThreadSafeClientConnManager(
			params, schReg);

	return new DefaultHttpClient(connMgr, params);
}
 
开发者ID:iQuick,项目名称:NewsMe,代码行数:23,代码来源:M3u8ContentParser.java

示例6: createHttpParams

import org.apache.http.conn.params.ConnManagerParams; //导入方法依赖的package包/类
private static HttpParams createHttpParams() {
	final HttpParams params = new BasicHttpParams();
	// 设置是否启用旧连接检查,默认是开启的。关闭这个旧连接检查可以提高一点点性能,但是增加了I/O错误的风险(当服务端关闭连接时)。
	// 开启这个选项则在每次使用老的连接之前都会检查连接是否可用,这个耗时大概在15-30ms之间
	HttpConnectionParams.setStaleCheckingEnabled(params, false);
	HttpConnectionParams.setConnectionTimeout(params, TIMEOUT);// 设置链接超时时间
	HttpConnectionParams.setSoTimeout(params, TIMEOUT);// 设置socket超时时间
	HttpConnectionParams.setSocketBufferSize(params, SOCKET_BUFFER_SIZE);// 设置缓存大小
	HttpConnectionParams.setTcpNoDelay(params, true);// 是否不使用延迟发送(true为不延迟)
	HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); // 设置协议版本
	HttpProtocolParams.setUseExpectContinue(params, true);// 设置异常处理机制
	HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);// 设置编码
	HttpClientParams.setRedirecting(params, false);// 设置是否采用重定向

	ConnManagerParams.setTimeout(params, TIMEOUT);// 设置超时
	ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(MAX_CONNECTIONS));// 多线程最大连接数
	ConnManagerParams.setMaxTotalConnections(params, 10); // 多线程总连接数
	return params;
}
 
开发者ID:cuilitang,项目名称:CuiMarket,代码行数:20,代码来源:HttpClientFactory.java

示例7: AsyncHttpClient

import org.apache.http.conn.params.ConnManagerParams; //导入方法依赖的package包/类
public AsyncHttpClient(SchemeRegistry schemeregistry)
{
    a = 10;
    b = 10000;
    h = true;
    BasicHttpParams basichttpparams = new BasicHttpParams();
    ConnManagerParams.setTimeout(basichttpparams, b);
    ConnManagerParams.setMaxConnectionsPerRoute(basichttpparams, new ConnPerRouteBean(a));
    ConnManagerParams.setMaxTotalConnections(basichttpparams, 10);
    HttpConnectionParams.setSoTimeout(basichttpparams, b);
    HttpConnectionParams.setConnectionTimeout(basichttpparams, b);
    HttpConnectionParams.setTcpNoDelay(basichttpparams, true);
    HttpConnectionParams.setSocketBufferSize(basichttpparams, 8192);
    HttpProtocolParams.setVersion(basichttpparams, HttpVersion.HTTP_1_1);
    ThreadSafeClientConnManager threadsafeclientconnmanager = new ThreadSafeClientConnManager(basichttpparams, schemeregistry);
    e = getDefaultThreadPool();
    f = new WeakHashMap();
    g = new HashMap();
    d = new SyncBasicHttpContext(new BasicHttpContext());
    c = new DefaultHttpClient(threadsafeclientconnmanager, basichttpparams);
    c.addRequestInterceptor(new a(this));
    c.addResponseInterceptor(new b(this));
    c.addRequestInterceptor(new c(this), 0);
    c.setHttpRequestRetryHandler(new z(5, 1500));
}
 
开发者ID:vishnudevk,项目名称:MiBandDecompiled,代码行数:26,代码来源:AsyncHttpClient.java

示例8: RESTMusicService

import org.apache.http.conn.params.ConnManagerParams; //导入方法依赖的package包/类
public RESTMusicService() {

        // Create and initialize default HTTP parameters
        HttpParams params = new BasicHttpParams();
        ConnManagerParams.setMaxTotalConnections(params, 20);
        ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(20));
        HttpConnectionParams.setConnectionTimeout(params, SOCKET_CONNECT_TIMEOUT);
        HttpConnectionParams.setSoTimeout(params, SOCKET_READ_TIMEOUT_DEFAULT);

        // Turn off stale checking.  Our connections break all the time anyway,
        // and it's not worth it to pay the penalty of checking every time.
        HttpConnectionParams.setStaleCheckingEnabled(params, false);

        // Create and initialize scheme registry
        SchemeRegistry schemeRegistry = new SchemeRegistry();
        schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        schemeRegistry.register(new Scheme("https", createSSLSocketFactory(), 443));

        // Create an HttpClient with the ThreadSafeClientConnManager.
        // This connection manager must be used if more than one thread will
        // be using the HttpClient.
        connManager = new ThreadSafeClientConnManager(params, schemeRegistry);
        httpClient = new DefaultHttpClient(connManager, params);
    }
 
开发者ID:MadMarty,项目名称:madsonic-5.5,代码行数:25,代码来源:RESTMusicService.java

示例9: ConnectionHelper

import org.apache.http.conn.params.ConnManagerParams; //导入方法依赖的package包/类
private ConnectionHelper() {
	HttpParams httpParams = new BasicHttpParams();
	ConnManagerParams.setMaxTotalConnections(httpParams,
			MAX_TOTAL_CONNECTIONS);
	ConnPerRouteBean connPerRoute = new ConnPerRouteBean(
			MAX_CONNECTIONS_PER_HOST);
	ConnManagerParams.setMaxConnectionsPerRoute(httpParams, connPerRoute);

	HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
	HttpProtocolParams.setUseExpectContinue(httpParams, false);
	SchemeRegistry reg = new SchemeRegistry();
	reg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(),
			80));
	reg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(),
			443));
	ThreadSafeClientConnManager connectionManager = new ThreadSafeClientConnManager(
			httpParams, reg);
	HttpConnectionParams.setConnectionTimeout(httpParams, CON_TIME_OUT_MS);
	HttpConnectionParams.setSoTimeout(httpParams, SO_TIME_OUT_MS);

	HttpClientParams.setCookiePolicy(httpParams,
			CookiePolicy.BROWSER_COMPATIBILITY);
	httpClient = new DefaultHttpClient(connectionManager, httpParams);
}
 
开发者ID:shenkaige,项目名称:AndroidHttpTools,代码行数:25,代码来源:ConnectionHelper.java

示例10: init

import org.apache.http.conn.params.ConnManagerParams; //导入方法依赖的package包/类
public void init() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory
            .getSocketFactory(), 80));
    HttpParams params = new BasicHttpParams();
    ConnManagerParams.setMaxTotalConnections(params, 10);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params,
            schemeRegistry);
    httpClient = new DefaultHttpClient(cm, params);
    // 重试
    // httpClient.setHttpRequestRetryHandler(new
    // DefaultHttpRequestRetryHandler(3, false));
    // 超时设置
    // httpClient.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT,
    // 10000);
    // httpClient.getParams().setIntParameter(HttpConnectionParams.SO_TIMEOUT,
    // 10000);
    httpClient.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS,
            true);

    threadNum = 10;
    execService = Executors.newFixedThreadPool(threadNum);
    destroy = false;
}
 
开发者ID:cobola,项目名称:smth3k,代码行数:26,代码来源:SmthCrawler.java

示例11: AndroidDispatchServiceAsync

import org.apache.http.conn.params.ConnManagerParams; //导入方法依赖的package包/类
public AndroidDispatchServiceAsync() {
	// Create and initialize HTTP parameters
	HttpParams params = new BasicHttpParams();
	
	ConnManagerParams.setMaxTotalConnections(params, 100);
	HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

	// Create and initialize scheme registry
	SchemeRegistry schemeRegistry = new SchemeRegistry();
	schemeRegistry.register(new Scheme("http", PlainSocketFactory
			.getSocketFactory(), 80));

	// Create an HttpClient with the ThreadSafeClientConnManager.
	// This connection manager must be used if more than one thread will
	// be using the HttpClient.
	ClientConnectionManager cm = new ThreadSafeClientConnManager(params,
			schemeRegistry);
	
	httpClient = HttpUtils.getHttpClient(cm);
	cookieStore = new CustomCookieStore();
}
 
开发者ID:Leejjon,项目名称:libgdx-chat-example,代码行数:22,代码来源:AndroidDispatchServiceAsync.java

示例12: generateHttpClient

import org.apache.http.conn.params.ConnManagerParams; //导入方法依赖的package包/类
public static HttpClient generateHttpClient(final int maxTotalConnections,
    final int maxTotalConnectionsPerRoute, int connTimeout) {
  HttpParams params = new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params, maxTotalConnections);
  ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRoute() {
    @Override
    public int getMaxForRoute(HttpRoute route) {
      return maxTotalConnectionsPerRoute;
    }
  });
  HttpConnectionParams
      .setConnectionTimeout(params, connTimeout);
  SchemeRegistry schemeRegistry = new SchemeRegistry();
  schemeRegistry.register(
      new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
  SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
  sslSocketFactory.setHostnameVerifier(SSLSocketFactory.
      ALLOW_ALL_HOSTNAME_VERIFIER);
  schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
  ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params,
      schemeRegistry);
  return new DefaultHttpClient(conMgr, params);
}
 
开发者ID:XiaoMi,项目名称:galaxy-sdk-java,代码行数:24,代码来源:EMQClientFactory.java

示例13: generateHttpClient

import org.apache.http.conn.params.ConnManagerParams; //导入方法依赖的package包/类
public static HttpClient generateHttpClient(final int maxTotalConnections,
                                            final int maxTotalConnectionsPerRoute, int connTimeout) {
  HttpParams params = new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params, maxTotalConnections);
  ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRoute() {
    @Override
    public int getMaxForRoute(HttpRoute route) {
      return maxTotalConnectionsPerRoute;
    }
  });
  HttpConnectionParams
      .setConnectionTimeout(params, connTimeout);
  SchemeRegistry schemeRegistry = new SchemeRegistry();
  schemeRegistry.register(
      new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
  SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
  sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
  schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
  ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schemeRegistry);
  return new DefaultHttpClient(conMgr, params);
}
 
开发者ID:XiaoMi,项目名称:galaxy-sdk-java,代码行数:22,代码来源:ClientFactory.java

示例14: generateHttpClient

import org.apache.http.conn.params.ConnManagerParams; //导入方法依赖的package包/类
public static HttpClient generateHttpClient(final int maxTotalConnections,
    final int maxTotalConnectionsPerRoute, int connTimeout) {
  HttpParams params = new BasicHttpParams();
  ConnManagerParams.setMaxTotalConnections(params, maxTotalConnections);
  ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRoute() {
    @Override
    public int getMaxForRoute(HttpRoute route) {
      return maxTotalConnectionsPerRoute;
    }
  });
  HttpConnectionParams
      .setConnectionTimeout(params, connTimeout);
  SchemeRegistry schemeRegistry = new SchemeRegistry();
  schemeRegistry.register(
      new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
  SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
  sslSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
  schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
  ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schemeRegistry);
  return new DefaultHttpClient(conMgr, params);
}
 
开发者ID:XiaoMi,项目名称:galaxy-sdk-java,代码行数:22,代码来源:MetricsClientFactory.java

示例15: createConnectionManager

import org.apache.http.conn.params.ConnManagerParams; //导入方法依赖的package包/类
private static synchronized ClientConnectionManager createConnectionManager() {
	if (connectionManager != null) {
		return connectionManager;
	}

	// Create and initialize scheme registry
	SchemeRegistry schemeRegistry = new SchemeRegistry();
	Scheme httpScheme = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
	//Scheme httpsScheme = new Scheme("https", SSLSocketFactory.getSocketFactory(), 443);
	Scheme httpsScheme = new Scheme("https", LibSSLSocketFactory.getSocketFactory(), 443);
	schemeRegistry.register(httpScheme);
	schemeRegistry.register(httpsScheme);

	HttpParams managerParams = new BasicHttpParams();
	//设置连接池允许的最大连接数
	ConnManagerParams.setMaxTotalConnections(managerParams, Constants.CONNECTION_POOL_SIZE);
	//设置连接池连接超时时间
	ConnManagerParams.setTimeout(managerParams, Constants.CONNECTION_TIME_OUT);
	connectionManager = new ThreadSafeClientConnManager(managerParams, schemeRegistry);

	return connectionManager;
}
 
开发者ID:cattong,项目名称:YiBo,代码行数:23,代码来源:HttpRequestHelper.java


注:本文中的org.apache.http.conn.params.ConnManagerParams.setMaxTotalConnections方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。