Nic*_*rta 3 java spring multithreading hashmap
我有许多带有自己的哈希图的服务,我的哈希图是不可变的,它们在初始化块中进行初始化。因此,所有线程都将读取哈希图,但不会对其进行写入。
我的服务是Spring的组件,所以它们是“Spring Singletons”。
使用HashMap来做这件事有什么问题吗?我应该使用其他课程吗?为什么?
这是我正在谈论的内容的一个例子:
@Service
public class TrackingServiceOne extends TrackingService {
Map<Integer, String> mapCreditos = new HashMap<Integer, String>();
Map<Integer, String> mapDeudas = new HashMap<Integer, String>();
Map<Integer, String> mapEjemplo = new HashMap<Integer, String>();
{
mapCreditos.put(1, "hi");
mapCreditos.put(2, "example");
// And like this I will populate each map.
}
// My methods will read the maps, never write them.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1413 次 |
| 最近记录: |