wood burning stoves 2.0*
The moose likes Java in General and the fly likes How to limit the execution time of a 3rd party method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to limit the execution time of a 3rd party method?" Watch "How to limit the execution time of a 3rd party method?" New topic
Author

How to limit the execution time of a 3rd party method?

Li Yang
Greenhorn

Joined: Sep 28, 2000
Posts: 7
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.
Yegor Bugayenko
Ranch Hand

Joined: Feb 11, 2011
Posts: 64
You can use AOP and a @Timeable annotation from jcabi-aspects:



When time limit is reached your thread will get `interrupted()` flag set to `true` and it's your job to handle this situation correctly and to stop execution.


follow me at yegor256.com
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
Does twelve years count as a long enough execution time?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to limit the execution time of a 3rd party method?
 
Similar Threads
set time limit for method
"APPLICATION'S DIGITAL SIGNATURE CANNOT BE VERIFIED" error
Help Required.
Get java.util.List from webservice
Ragarding manifest.mf