Skip to content

Commit 16914c8

Browse files
quafffmbenhassine
authored andcommitted
Polish SynchronizationManagerSupport to use Map::computeIfAbsent
Signed-off-by: Yanming Zhou <[email protected]>
1 parent 74e4d2f commit 16914c8

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/SynchronizationManagerSupport.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2021 the original author or authors.
2+
* Copyright 2013-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@
2828
* @author Dave Syer
2929
* @author Jimmy Praet
3030
* @author Mahmoud Ben Hassine
31+
* @author Yanming Zhou
3132
* @since 3.0
3233
*/
3334
public abstract class SynchronizationManagerSupport<E, C> {
@@ -87,11 +88,7 @@ public C register(@Nullable E execution) {
8788
getCurrent().push(execution);
8889
C context;
8990
synchronized (contexts) {
90-
context = contexts.get(execution);
91-
if (context == null) {
92-
context = createNewContext(execution);
93-
contexts.put(execution, context);
94-
}
91+
context = contexts.computeIfAbsent(execution, this::createNewContext);
9592
}
9693
increment();
9794
return context;
@@ -131,11 +128,7 @@ public void increment() {
131128
if (current != null) {
132129
AtomicInteger count;
133130
synchronized (counts) {
134-
count = counts.get(current);
135-
if (count == null) {
136-
count = new AtomicInteger();
137-
counts.put(current, count);
138-
}
131+
count = counts.computeIfAbsent(current, k -> new AtomicInteger());
139132
}
140133
count.incrementAndGet();
141134
}

0 commit comments

Comments
 (0)