Skip to content

Commit 38fab27

Browse files
authored
Replace HashMap with ConcurrentHashMap for thread-safe caching in FindRepositoriesByUserIdCache and findRepositories method (#345)
1 parent eb9147f commit 38fab27

File tree

1 file changed

+2
-2
lines changed
  • src/data/articles/structured-concurrency-jdk-25

1 file changed

+2
-2
lines changed

src/data/articles/structured-concurrency-jdk-25/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ We can copy from the previous article the implementation of the `FindRepositorie
384384
```java
385385
class FindRepositoriesByUserIdCache implements FindRepositoriesByUserIdPort {
386386
387-
private final Map<UserId, List<Repository>> cache = new HashMap<>();
387+
private final Map<UserId, List<Repository>> cache = new ConcurrentHashMap<>();
388388
389389
public FindRepositoriesByUserIdCache() {
390390
cache.put(
@@ -504,7 +504,7 @@ class GitHubRepository
504504
@Override
505505
public Map<UserId, List<Repository>> findRepositories(List<UserId> userIds)
506506
throws InterruptedException {
507-
var repositoriesByUserId = new HashMap<UserId, List<Repository>>();
507+
var repositoriesByUserId = new ConcurrentHashMap<UserId, List<Repository>>();
508508
try (var scope = StructuredTaskScope.open(Joiner.awaitAll())) {
509509
userIds.forEach(
510510
userId -> {

0 commit comments

Comments
 (0)