在java中设置方法的运行时间限制 [英] Set running time limit on a method in java
本文介绍了在java中设置方法的运行时间限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个返回String的方法,是否有可能在某个时间阈值之后,该方法返回一些特定的字符串?
I have a method that returns a String, is it possible that after a certain time treshold is excedeed fot that method to return some specific string?
推荐答案
Guava库有一个非常好的 TimeLimiter
,允许您对接口定义的任何方法执行此操作。它可以为您的对象生成具有内置超时的代理。
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.
这篇关于在java中设置方法的运行时间限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文