Skip to content
Advertisement

Set running time limit on a method in java

I have a method that returns a String.

Is it possible that after a certain time, if threshold is excedeed for that method, to return some specific string?

Advertisement

Answer

The Guava library has a very nice TimeLimiter that lets you do this on any method that’s defined by an interface. It can generate a proxy for your object that has a “built-in” timeout.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement