另一種替代的辦法是放棄用戶類型和屬性模型作爲InputStream
public Thing {
// use field access level
private InputStream blob;
@Tranisent
private Future<That> that;
private static final ExecutorService executor = ExecutorService.newCachedThreadPool();
public Future<That> getThat(){
if(that == null) {
// lazily submit the creation to the executor
that = executor.submit(new Callable<That>{/* implement call() */});
}
return that;
}
}
認爲這可能是一點點更平易近人是的Future<That>
注意的用戶類型,當你清單Thing
在實際嘗試訪問這些值之前,您首先需要填充對象:
for(Thing thing: listOfThings){
thing.getThat() ; // for side effects
}
for(Thing thing: listOfThings){
That that = thing.getThat().get();
}
這有幾個問題。
- Executor沒有明確的生命週期。即如何將它被關閉
- 沒有保證,在列表中的第一個項目將是第一個返回結果,也許用
ExecutorCompletationService
將提供更好的解決方案
數據是完好的擔保,當從Hibernate切換到用戶代碼是必須的。因此,對於個體期貨而言,直接問題是同步響應,即結果集中的所有對象都具有有效屬性(即,在我的情況下,解析字符串是JAXB對象)。 – 2011-12-15 06:43:35