<dependency>
<groupId>com.chilldev.commons.concurrent</groupId>
<artifactId>chill-commons-concurrent</artifactId>
<version>1.0.0</version>
</dependency>
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class ConcurrentDataExample {
private static Map<String, Integer> dataMap = new ConcurrentHashMap<>();
public static void main(String[] args) {
Thread thread1 = new Thread(() -> {
for (int i = 0; i < 100; i++) {
dataMap.put(String.valueOf(i), i);
}
});
Thread thread2 = new Thread(() -> {
for (int i = 100; i < 200; i++) {
dataMap.put(String.valueOf(i), i);
}
});
thread1.start();
thread2.start();
try {
thread1.join();
thread2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
dataMap.forEach((key, value) -> System.out.println(key + ": " + value));
}
}