[英]Behavior of HttpClient with caller thread being cancelled
We have a callable class A
which actually makes HttpCalls through HttpClient.executeMethod(GetMethod)
with a lot of other pre-computations. 我们有一个可调用的class A
,它实际上通过HttpClient.executeMethod(GetMethod)
与许多其他预计算进行HttpCalls。 HttpClient is initialized in the constructor with MultiThreadedHttpConnectionManager
. 使用MultiThreadedHttpConnectionManager
在构造函数中初始化HttpClient。
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. 另一个class B
通过ExecutorService
为类A创建线程列表,并将任务提交给池,并期望将来返回对象。 We have following logic in class B: 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: 我要确认以下几点:
Thanks! 谢谢!
It depends. 这取决于。
If the Http Client
uses java.net.Socket,
its I/O isn't interrruptible, so the cancel will have no effect. 如果Http Client
使用java.net.Socket,
其I / O不会中断,因此取消将无效。
If it uses NIO, the interrupt will close the channel and cause an exception. 如果使用NIO,则中断将关闭通道并导致异常。 At the server this will cause a premature end of stream or an exception on write, either of which the server should cope with corectly. 在服务器上,这将导致流过早结束或写入异常,服务器应严格解决这两种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.