class A implements Callable{
List result // want to share this List amongst thread and their function call
public Search call() {
List<Job> Jobs = api. Jobs(a,b,c); // Multiple threads
}
}
class API{
public void jobs(a,b,c){
// want to access the A.Result and populate the result
}
}
我如何在所有线程中共享一个数组列表,我不想使用静态, 因为它每次运行时都会不断累积结果, Thread Local 是一个不错的选择吗?
试图避免额外的对象及其各自的 getter/setter?
最佳答案
你现在拥有的是线程共享列表。操作该对象的所有线程 (假设该对象只存在一个实例)除非同步,否则共享相同的列表。
关于java - 如何在Java中的所有线程中维护List的单个副本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11894731/