On this page
  1. ConcurrentHashMap
  2. Import
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

ConcurrentHashMap

Prev: `CompletableFuture` | Up: java.util.concurrent | Next: `ReentrantLock`
Rel: java.util.concurrent, java/builtins
Ref: Java Docs — ConcurrentHashMap
Tags: #public #prog #java #stdlib #java_util_concurrent #tier/core


Import

import java.util.concurrent.*;

Signature & Overview

ConcurrentHashMap<K, V>

High-concurrency thread-safe hash map using lock striping / CAS (no global lock on reads).

Notes & Pitfalls

Example

import java.util.concurrent.ConcurrentHashMap;

var counts = new ConcurrentHashMap<String, Integer>();
counts.merge("req", 1, Integer::sum);
counts.merge("req", 1, Integer::sum);
assert counts.get("req") == 2;

Linked from

Related notes