org.apache.commons.httpclient.HttpClient 多线程调用崩溃

org.apache.commons.httpclient.HttpClient multithreading calls crash

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

这是我的代码。

        httpClient = new HttpClient();

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

           ... method creation...

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

提前致谢。娟

你看过 HttpClient threading documentation 了吗?

To get started one must create an instance of the MultiThreadedHttpConnectionManager and give it to an HttpClient. This looks something like:

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

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