【问题标题】:org.apache.commons.httpclient.HttpClient multithreading calls crashorg.apache.commons.httpclient.HttpClient 多线程调用崩溃
【发布时间】:2015-03-10 20:47:42
【问题描述】:

大家好,我使用 apache 的 httpclient 进行 restcalls,一切正常,当多个线程使用此方法时,我的应用程序崩溃。 MultithreadSafe 这个类的实现是什么。

这是我的代码。

        httpClient = new HttpClient();

        HttpMethod method = null;
        method = new GetMethod();

           ... method creation...

        httpClient.executeMethod(method);
        method.releaseConnection();

提前致谢。娟

【问题讨论】:

标签: apache apache-commons apache-commons-httpclient


【解决方案1】:

你看过HttpClientthreading documentation吗?

要开始,必须创建一个 MultiThreadedHttpConnectionManager 并将其提供给 HttpClient。这 看起来像:

      MultiThreadedHttpConnectionManager connectionManager = 
          new MultiThreadedHttpConnectionManager();
      HttpClient client = new HttpClient(connectionManager);

您在使用 HttpClient 时遇到的问题很常见开箱即用

【讨论】:

  • 非常感谢布赖恩。有没有办法正确测试这个并发问题?
猜你喜欢
  • 1970-01-01
  • 2012-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-05
相关资源
最近更新 更多