I create a ThreadPool with 10 fixed threads in it. At times I need to interrupt a longrunning thread in the thread pool, mostly because they are blocking in some operation and a timeout happens and I interrupt the thread. I catch the InterruptedException and set the Thread's status to interrupt as well. In that case, my question is, does ThreadPool create a new Thread and replace the interrupted thread with a new One ?
Below is the example code which gets executed by the Thread. Question is, when this thread get interrupted, does thread pool replace this thread with a new one ?
public ResponseMessage call(){
Future<ResponseMessage> future = CacheManager.getInstance().asyncFetch();
ResponseMessage response = null;
try {
response = future.get();
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (ExecutionException ex) {
//create a blank response
}
return response;
}
get()has an overload that accepts a time-out, right? - erickson