We have a callable class A
which actually makes HttpCalls through HttpClient.executeMethod(GetMethod)
with a lot of other pre-computations. HttpClient is initialized in the constructor with MultiThreadedHttpConnectionManager
.
Another class B
creates list of threads for class A through ExecutorService
and submits task to the pool and expects future objects to be returned. We have following logic in class B:
for( Future f : futures ){
try{
String str = f.get(timeOut, TimeUnit.SECONDS);
}catch(TimeoutException te){
f.cancel(true);
}
}
This way, our thread gets terminated after a specified time and execution of the task will be terminated and this thread will be available for next task.
I want to confirm the following:
- If an external connection is made though HttpClient, how does that get handled on future.cancel of the thread?
- In above case or in general, does the http connection pool gets the connection back by properly releasing the previous one? We do release the connection in finally but I don't think interrupting the thread will hit that block.
- Could it cause any kind of leak on client or extra resource consumption on the server?
Thanks!