I need to call an external method which sometimes takes indefinite time to complete.
void doMyStuff(){
// do my stuff
// work is being done by doStuff thread
externalMethod(); // This is external and sometimes takes hours
// I need to check if current thread is interrupted and then return after a certain time
}
However, I can't afford to keep a thread engaged, so I need to terminate the process after a fixed time. I can interrupt the doStuff thread from an external thread with the help of Websphere's WorkManager API. But only sending the interrupt signal is useless unless the interrupted thread handles it.
I want to return the doStuff thread to thread pool after a certain time no matter whether the extenalMethod()
returns or not. How can this be done?