重试任务框架 [英] Retry Task Framework
问题描述
我有很多情况需要在失败的情况下重试任务n次(有时会使用某种形式的重试前退避逻辑)。通常,如果抛出异常,则应该重试任务以达到最大重试次数。
I have a number of situations where I need to retry a task n-times if it fails (sometimes with some form of back-off-before-retry logic). Generally, if an exception is thrown, the task should be retried up to the max-retry count.
我可以轻松地写一些东西来做到这一点相当一般,但不想要重新发明轮子我想知道是否有人可以推荐任何框架。我唯一能找到的是: Ant Retry 但我不知道我想直接在我的应用程序中使用Ant任务。
I can easily write something to do this fairly generically, but not wanting to re-invent the wheel I was wondering if anyone can recommend any frameworks for this. The only thing I have been able to find is: Ant Retry but I don't want to use Ant tasks directly in my application.
谢谢
推荐答案
您可以使用<$ href =http://fahdshariff.blogspot.com/2009/08/retrying-operations-in-中列出的 RetriableTasks
java.htmlrel =noreferrer>在Java中重试操作。如果你愿意,你可以很容易地改变它的等待算法。
You can use RetriableTasks
as outlined in this post: Retrying Operations in Java. You can quite easily change its waiting algorithm if you like.
示例代码:
//creates a task which will retry 3 times with an interval of 5 seconds
RetriableTask r = new RetriableTask(3, 5000, new Callable(){
public Object call() throws Exception{
//put your code here
}
});
r.call();
这篇关于重试任务框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!