Is there a clean or non-deprecated way to limit the execution time of a method of a 3rd party object? Explanation: I encountered a situation in which I need to invoke a method of a 3rd party object that potenially will hang forever. Using a thread and the stop(), I can limit the execution time of that method. Are there any alternatives? Thanks.
Alternatively, you can run that operation with an Executor, and use a FutureTask to submit the task and wait a maximum amount of time for it to finish. You won't necessarily be able to force the subtask to stop executing, but you can allow the code that was waiting on it to move on.