【发布时间】:2012-12-27 14:16:45
【问题描述】:
我有以下问题:
我有一些方法基本上是用来从 Salesforce 获取东西的。
这是一个例子:
public Map<String, Customer> findSomethingByIds(String[] somethingIds) throws... {
return binding.findSomethingByIds(somethingIds);
}
出于多种原因,我需要在极少数情况下(例如会话过期等)重试执行此方法,因此我使用了this。
所以现在我有这样的东西:
public Map<String, Something> findSomethingByIds(final String[] somethingIds) throws ... {
Map<String, Something> myList = null;
Callable<Map<String, Something>> task = new Callable<Map<String, Something>>() {
@Override
public Map<String, Something> call() throws Exception {
return binding.findSomethingByIds(somethingIds);
}
};
RetriableTask<Map<String, Something>> r = new RetriableTask<>(2, 1000, task);
try {
myList = r.call();
} catch (Exception e) {
// Ex. handling
}
return myList;
}
现在,我的代码中有很多这样的方法,所以如果我想使用 RetriableTask 接口,我必须在这些方法中添加很多代码,类似于上面的那个,我想完全避免费用。所有这些方法几乎都返回不同的东西,所以我不能在这里使用工厂(或者我不知道如何使用)。有谁知道任何解决方案?任何帮助将不胜感激。
【问题讨论】:
-
你考虑过使用通用静态方法吗?
标签: java exception-handling refactoring salesforce