另一种替代的办法是放弃用户类型和属性模型作为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