I have a java thread which performs some heavy database operation. I am coding an api to kill this java thread. I am using executor framework for this, so once i get future, i call future.cancel() and then check for thread interruption.
Above logic works fine except the scenarions where thread is performing DB operation, which imples that killing a thread will first involve killing DB connection which means DBA intervention.
My aim is to create an api which doesn't need any intervention from support teams.
Any ideas on how to go about this will be extremely helpful.
CODE:
private void killBatches1() {
if (killBatchRunning.compareAndSet(false, true)) {
try{
Iterator<Future<?>> futureIterator = futuresForBatch.iterator();
while (futureIterator.hasNext()) {
Future<?> future = futureIterator.next();
if (future.cancel(true))
;
futureIterator.remove();
}
}finally{
killBatchRunning.set(false);
}
}
order bytakes more time for this 2%. Every request has 10 inputs and each time, one of the input can come from this 2% data. My only thought out solution is to have an estimate of blocked out threads per second and increase the size of thread pool such that thread pool does not reach its limit and block subsequent requests.