8

I'm writing a swing application with HttpClient 4.

I followed the standard approach by passing a ThreadSafeClientConnManager to my shared HttpClient instance for now. But now I would like to be able to execute multiple requests/downloads at the same time...

I found some examples with MultiThreadedHttpConnectionManager for HttpClient 3.x but can I use it for version 4.x ? If so how ? I tried it but without success...

Thanks ;)

Sastrija
  • 3,284
  • 6
  • 47
  • 64
Hervé Donner
  • 523
  • 1
  • 6
  • 13

2 Answers2

16

In 4.x, the equivalent is Pooling connection manager. You can read more details on its usage in section Pooling connection manager here. I would also strongly suggest you to read this thread on their forum.

XoXo
  • 1,560
  • 1
  • 16
  • 35
Aravind Yarram
  • 78,777
  • 46
  • 231
  • 327
1

There's no indication in the javadoc that a DefaultHttpClient instance is thread-safe.

So, I think you should just create an HttpClient instance for each activity ... using a common/shared ThreadSafeClientConnManager instance. That should allow you to reuse connections between HttpClient instances. Just make sure that you don't shut down the connection manager.

The APIs are sufficiently different between version 3.x and 4.x that I'd be surprised if the examples for one were instructive for the other.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216