diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/SynchronizationManagerSupport.java b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/SynchronizationManagerSupport.java index 1891f55883..f76a48b55a 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/SynchronizationManagerSupport.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/scope/context/SynchronizationManagerSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2021 the original author or authors. + * Copyright 2013-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ * @author Dave Syer * @author Jimmy Praet * @author Mahmoud Ben Hassine + * @author Yanming Zhou * @since 3.0 */ public abstract class SynchronizationManagerSupport { @@ -87,11 +88,7 @@ public C register(@Nullable E execution) { getCurrent().push(execution); C context; synchronized (contexts) { - context = contexts.get(execution); - if (context == null) { - context = createNewContext(execution); - contexts.put(execution, context); - } + context = contexts.computeIfAbsent(execution, this::createNewContext); } increment(); return context; @@ -131,11 +128,7 @@ public void increment() { if (current != null) { AtomicInteger count; synchronized (counts) { - count = counts.get(current); - if (count == null) { - count = new AtomicInteger(); - counts.put(current, count); - } + count = counts.computeIfAbsent(current, k -> new AtomicInteger()); } count.incrementAndGet(); }