My main process calls an external library method. This method sometimes hangs. I can not fix the external library because another company is responsible for it.
I want to use a Thread for the library calls with a defined execution timer. When the method call takes to long, the Thread with the Runnable in which the method call is placed should stop and the main process should go forward.
- Main Thread wait
- Execute Thread
- start Start timer Thread
- When timer thread is finished kill Execute Thread
- Execute Thread stop Main
- thread resume
Does anybody have some code this logic is for, a design pattern i can use or a internet page i can read some informations?
Thanks
Take a look at the
java.lang.concurrentpackage in Java 5 and later, in particular theCompletionServiceinterface and the classes that implement it.This interface includes calls that allow you to submit a task and either wait for it to complete, or else continue after a timeout.