반응형
이전 포스팅에서 ConcurrentHashMap 에 대해서 다룬 글이 있다.
자세한 내용은 아래 참고 포스팅 참고 바란다.
ConcurrentHashMap 은 일단 Collections 중 하나인 map 과 비슷한데 Key Value 로 나뉜다.
그러면서 key마다 value에 각각 thread 별로 데이터를 넣어주면 동시성 제어가 된다는 의미이다.
예제로 확인해보면 아래와 같다.
참고로 코드에서 사용중인 Thread에 대한 정보는 아래 참고 포스팅을 확인해보면 Thread 정보를 가져오는 법을 알수 있다.
..이상 생략 private final Map<String, List<CustEntity>> entities = new ConcurrentHashMap<>(); public void setEntities(String key, List<CustEntity> entities) { sharedEntities.put(key, entities); } public List<CustEntity> getEntities(String key) { return sharedEntities.get(key); } public test() { Thread mainThread = Thread.currentThread(); // 현재 쓰레드 얻기 .. //데이터 저장 entities.put(mainThread.toString(), entityList); //데이터 로딩 entities.get(mainThread.toString()); } |
참고 포스팅
https://thenicesj.tistory.com/349
HashTable, HashMap, ConcurrentHashMap 비교
이전 포스팅에서 Map에 대해서 다룬적은 있다.자세한 내용은 아래 참고 포스팅을 확인해보길 추천한다. 이번 포스팅에서는 Hash 관련해서 HashTable, HashMap, ConcurrentHashMap 세개를 얘기해볼 것이다.
thenicesj.tistory.com
https://thenicesj.tistory.com/1024
자바에서 Thread 확인
자바에서 실행의 주체가 되는것은 Thread 라고 설명을 이전 포스팅에서 몇 했었다.자세한 내용은 아래 참고 포스팅 참고 바란다. 이번 포스팅에서는 현재 실행되고 있는 Thread가 어떤 Thread 인지
thenicesj.tistory.com
반응형
'IT > Java' 카테고리의 다른 글
@Valid 를 Dto 에 적용하기 (7) | 2024.08.18 |
---|---|
[Error] An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments (17) | 2024.08.17 |
ThreadPool Default (21) | 2024.08.15 |
자바에서 Thread 확인 (6) | 2024.08.14 |
MockMvc Get, Post, Put, Delete 테스트 (24) | 2024.08.13 |
댓글