http connection timeout issues

前端 未结 10 1597
感情败类
感情败类 2020-12-13 20:54

I\'m running into an issue when i try to use the HttpClient connecting to a url. The http connection is taking a longer time to timeout, even after i set a connection timeoo

10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 21:17

    Thread t=new Thread()
    {
      public void run()
      {
        try 
        {
          Thread.sleep(absolutetimeout);
          httpclient.getConnectionManager().closeExpiredConnections();
          httpclient.getConnectionManager().closeIdleConnections(absolutetimeout,TimeUnit.MILLISECONDS);
          httpclient.getConnectionManager().shutdown();
          log.debug("We shutdown the connection manager!");
        }
        catch(InterruptedException e)
        {}
      }
    };
    
    t.start();
    HttpResponse res= httpclient.execute(httpget);
    t.interrupt();
    

    Is that along the lines of what you all are suggesting?

    I'm not exactly sure how to cancel the execute once it has started, but this seemed to work for me. I'm not sure which of the three lines in the thread did the magic, or if it was some combination of all of them.

提交回复
热议问题