From 3b9ceea0b443fd1c17fbd8250d95ae48257de0d6 Mon Sep 17 00:00:00 2001 From: Seungrae Date: Thu, 23 May 2024 02:53:28 +0900 Subject: [PATCH] Use Threadlocal.remove() instead of Threadlocal.set(null) Issue #4601 --- .../batch/core/job/flow/JobFlowExecutor.java | 6 +++--- .../springframework/batch/core/step/item/ChunkMonitor.java | 5 +++-- .../batch/repeat/support/RepeatSynchronizationManager.java | 7 ++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/JobFlowExecutor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/JobFlowExecutor.java index 982704057..c1583e25f 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/JobFlowExecutor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/JobFlowExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2022 the original author or authors. + * Copyright 2006-2024 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. @@ -35,6 +35,7 @@ import org.springframework.lang.Nullable; * @author Dave Syer * @author Michael Minella * @author Mahmoud Ben Hassine + * @author Seungrae Kim * */ public class JobFlowExecutor implements FlowExecutor { @@ -58,7 +59,6 @@ public class JobFlowExecutor implements FlowExecutor { this.jobRepository = jobRepository; this.stepHandler = stepHandler; this.execution = execution; - stepExecutionHolder.set(null); } @Override @@ -118,7 +118,7 @@ public class JobFlowExecutor implements FlowExecutor { @Override public void close(FlowExecution result) { - stepExecutionHolder.set(null); + stepExecutionHolder.remove(); } @Override diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkMonitor.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkMonitor.java index ae83b261c..47ac07107 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkMonitor.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/ChunkMonitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2023 the original author or authors. + * Copyright 2006-2024 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. @@ -32,6 +32,7 @@ import org.springframework.batch.item.support.CompositeItemStream; * * @author Dave Syer * @author Mahmoud Ben Hassine + * @author Seungrae Kim * @since 2.0 */ public class ChunkMonitor extends ItemStreamSupport { @@ -104,7 +105,7 @@ public class ChunkMonitor extends ItemStreamSupport { @Override public void close() throws ItemStreamException { super.close(); - holder.set(null); + holder.remove(); if (streamsRegistered) { stream.close(); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatSynchronizationManager.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatSynchronizationManager.java index 8a809cfca..c05713854 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatSynchronizationManager.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/support/RepeatSynchronizationManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2024 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. @@ -30,6 +30,7 @@ import org.springframework.batch.repeat.RepeatOperations; * {@link RepeatOperations} implementations. * * @author Dave Syer + * @author Seungrae Kim * */ public final class RepeatSynchronizationManager { @@ -70,7 +71,7 @@ public final class RepeatSynchronizationManager { */ public static RepeatContext register(RepeatContext context) { RepeatContext oldSession = getContext(); - RepeatSynchronizationManager.contextHolder.set(context); + contextHolder.set(context); return oldSession; } @@ -81,7 +82,7 @@ public final class RepeatSynchronizationManager { */ public static RepeatContext clear() { RepeatContext context = getContext(); - RepeatSynchronizationManager.contextHolder.set(null); + contextHolder.remove(); return context; }