Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Replace HashMap with ConcurrentHashMap for thread-safe caching in Fin…
…dRepositoriesByUserIdCache and findRepositories method
  • Loading branch information
rcardin committed Sep 11, 2025
commit 0c138f3f3dec240e8c4acb2c33fa18472b85c280
4 changes: 2 additions & 2 deletions src/data/articles/structured-concurrency-jdk-25/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ We can copy from the previous article the implementation of the `FindRepositorie
```java
class FindRepositoriesByUserIdCache implements FindRepositoriesByUserIdPort {

private final Map<UserId, List<Repository>> cache = new HashMap<>();
private final Map<UserId, List<Repository>> cache = new ConcurrentHashMap<>();

public FindRepositoriesByUserIdCache() {
cache.put(
Expand Down Expand Up @@ -504,7 +504,7 @@ class GitHubRepository
@Override
public Map<UserId, List<Repository>> findRepositories(List<UserId> userIds)
throws InterruptedException {
var repositoriesByUserId = new HashMap<UserId, List<Repository>>();
var repositoriesByUserId = new ConcurrentHashMap<UserId, List<Repository>>();
try (var scope = StructuredTaskScope.open(Joiner.awaitAll())) {
userIds.forEach(
userId -> {
Expand Down