Skip to content

Commit ad61fb7

Browse files
committed
Polishing
1 parent c5aa783 commit ad61fb7

File tree

7 files changed

+44
-45
lines changed

7 files changed

+44
-45
lines changed

spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -79,10 +79,11 @@ public SimpleApplicationEventMulticaster(BeanFactory beanFactory) {
7979
* to invoke each listener with.
8080
* <p>Default is equivalent to {@link org.springframework.core.task.SyncTaskExecutor},
8181
* executing all listeners synchronously in the calling thread.
82-
* <p>Consider specifying an asynchronous task executor here to not block the
83-
* caller until all listeners have been executed. However, note that asynchronous
84-
* execution will not participate in the caller's thread context (class loader,
85-
* transaction association) unless the TaskExecutor explicitly supports this.
82+
* <p>Consider specifying an asynchronous task executor here to not block the caller
83+
* until all listeners have been executed. However, note that asynchronous execution
84+
* will not participate in the caller's thread context (class loader, transaction context)
85+
* unless the TaskExecutor explicitly supports this.
86+
* @since 2.0
8687
* @see org.springframework.core.task.SyncTaskExecutor
8788
* @see org.springframework.core.task.SimpleAsyncTaskExecutor
8889
*/
@@ -92,6 +93,7 @@ public void setTaskExecutor(@Nullable Executor taskExecutor) {
9293

9394
/**
9495
* Return the current task executor for this multicaster.
96+
* @since 2.0
9597
*/
9698
@Nullable
9799
protected Executor getTaskExecutor() {

spring-context/src/test/java/org/springframework/scheduling/annotation/EnableSchedulingTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void withFixedRateTask() throws InterruptedException {
6363
ctx = new AnnotationConfigApplicationContext(FixedRateTaskConfig.class);
6464
assertThat(ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks()).hasSize(2);
6565

66-
Thread.sleep(100);
66+
Thread.sleep(110);
6767
assertThat(ctx.getBean(AtomicInteger.class).get()).isGreaterThanOrEqualTo(10);
6868
}
6969

@@ -73,7 +73,7 @@ public void withSubclass() throws InterruptedException {
7373
ctx = new AnnotationConfigApplicationContext(FixedRateTaskConfigSubclass.class);
7474
assertThat(ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks()).hasSize(2);
7575

76-
Thread.sleep(100);
76+
Thread.sleep(110);
7777
assertThat(ctx.getBean(AtomicInteger.class).get()).isGreaterThanOrEqualTo(10);
7878
}
7979

@@ -83,7 +83,7 @@ public void withExplicitScheduler() throws InterruptedException {
8383
ctx = new AnnotationConfigApplicationContext(ExplicitSchedulerConfig.class);
8484
assertThat(ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks()).hasSize(1);
8585

86-
Thread.sleep(100);
86+
Thread.sleep(110);
8787
assertThat(ctx.getBean(AtomicInteger.class).get()).isGreaterThanOrEqualTo(10);
8888
assertThat(ctx.getBean(ExplicitSchedulerConfig.class).threadName).startsWith("explicitScheduler-");
8989
assertThat(Arrays.asList(ctx.getDefaultListableBeanFactory().getDependentBeans("myTaskScheduler")).contains(
@@ -102,7 +102,7 @@ public void withExplicitScheduledTaskRegistrar() throws InterruptedException {
102102
ctx = new AnnotationConfigApplicationContext(ExplicitScheduledTaskRegistrarConfig.class);
103103
assertThat(ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks()).hasSize(1);
104104

105-
Thread.sleep(100);
105+
Thread.sleep(110);
106106
assertThat(ctx.getBean(AtomicInteger.class).get()).isGreaterThanOrEqualTo(10);
107107
assertThat(ctx.getBean(ExplicitScheduledTaskRegistrarConfig.class).threadName).startsWith("explicitScheduler1");
108108
}
@@ -124,7 +124,7 @@ public void withAmbiguousTaskSchedulers_andSingleTask_disambiguatedByScheduledTa
124124
ctx = new AnnotationConfigApplicationContext(
125125
SchedulingEnabled_withAmbiguousTaskSchedulers_andSingleTask_disambiguatedByScheduledTaskRegistrar.class);
126126

127-
Thread.sleep(100);
127+
Thread.sleep(110);
128128
assertThat(ctx.getBean(ThreadAwareWorker.class).executedByThread).startsWith("explicitScheduler2-");
129129
}
130130

@@ -134,7 +134,7 @@ public void withAmbiguousTaskSchedulers_andSingleTask_disambiguatedBySchedulerNa
134134
ctx = new AnnotationConfigApplicationContext(
135135
SchedulingEnabled_withAmbiguousTaskSchedulers_andSingleTask_disambiguatedBySchedulerNameAttribute.class);
136136

137-
Thread.sleep(100);
137+
Thread.sleep(110);
138138
assertThat(ctx.getBean(ThreadAwareWorker.class).executedByThread).startsWith("explicitScheduler2-");
139139
}
140140

@@ -143,7 +143,7 @@ public void withAmbiguousTaskSchedulers_andSingleTask_disambiguatedBySchedulerNa
143143
public void withTaskAddedVia_configureTasks() throws InterruptedException {
144144
ctx = new AnnotationConfigApplicationContext(SchedulingEnabled_withTaskAddedVia_configureTasks.class);
145145

146-
Thread.sleep(100);
146+
Thread.sleep(110);
147147
assertThat(ctx.getBean(ThreadAwareWorker.class).executedByThread).startsWith("taskScheduler-");
148148
}
149149

@@ -152,7 +152,7 @@ public void withTaskAddedVia_configureTasks() throws InterruptedException {
152152
public void withTriggerTask() throws InterruptedException {
153153
ctx = new AnnotationConfigApplicationContext(TriggerTaskConfig.class);
154154

155-
Thread.sleep(100);
155+
Thread.sleep(110);
156156
assertThat(ctx.getBean(AtomicInteger.class).get()).isGreaterThan(1);
157157
}
158158

spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -85,7 +85,7 @@ public abstract class ConnectionFactoryUtils {
8585
*/
8686
public static Mono<Connection> getConnection(ConnectionFactory connectionFactory) {
8787
return doGetConnection(connectionFactory)
88-
.onErrorMap(e -> new DataAccessResourceFailureException("Failed to obtain R2DBC Connection", e));
88+
.onErrorMap(ex -> new DataAccessResourceFailureException("Failed to obtain R2DBC Connection", ex));
8989
}
9090

9191
/**
@@ -124,17 +124,17 @@ public static Mono<Connection> doGetConnection(ConnectionFactory connectionFacto
124124
holderToUse.setConnection(conn);
125125
}
126126
holderToUse.requested();
127-
synchronizationManager
128-
.registerSynchronization(new ConnectionSynchronization(holderToUse, connectionFactory));
127+
synchronizationManager.registerSynchronization(
128+
new ConnectionSynchronization(holderToUse, connectionFactory));
129129
holderToUse.setSynchronizedWithTransaction(true);
130130
if (holderToUse != conHolder) {
131131
synchronizationManager.bindResource(connectionFactory, holderToUse);
132132
}
133133
}) // Unexpected exception from external delegation call -> close Connection and rethrow.
134-
.onErrorResume(e -> releaseConnection(connection, connectionFactory).then(Mono.error(e))));
134+
.onErrorResume(ex -> releaseConnection(connection, connectionFactory).then(Mono.error(ex))));
135135
}
136136
return con;
137-
}).onErrorResume(NoTransactionException.class, e -> Mono.from(connectionFactory.create()));
137+
}).onErrorResume(NoTransactionException.class, ex -> Mono.from(connectionFactory.create()));
138138
}
139139

140140
/**
@@ -159,7 +159,7 @@ private static Mono<Connection> fetchConnection(ConnectionFactory connectionFact
159159
*/
160160
public static Mono<Void> releaseConnection(Connection con, ConnectionFactory connectionFactory) {
161161
return doReleaseConnection(con, connectionFactory)
162-
.onErrorMap(e -> new DataAccessResourceFailureException("Failed to close R2DBC Connection", e));
162+
.onErrorMap(ex -> new DataAccessResourceFailureException("Failed to close R2DBC Connection", ex));
163163
}
164164

165165
/**
@@ -171,15 +171,14 @@ public static Mono<Void> releaseConnection(Connection con, ConnectionFactory con
171171
* @see #doGetConnection
172172
*/
173173
public static Mono<Void> doReleaseConnection(Connection connection, ConnectionFactory connectionFactory) {
174-
return TransactionSynchronizationManager.forCurrentTransaction()
175-
.flatMap(synchronizationManager -> {
174+
return TransactionSynchronizationManager.forCurrentTransaction().flatMap(synchronizationManager -> {
176175
ConnectionHolder conHolder = (ConnectionHolder) synchronizationManager.getResource(connectionFactory);
177176
if (conHolder != null && connectionEquals(conHolder, connection)) {
178177
// It's the transactional Connection: Don't close it.
179178
conHolder.released();
180179
}
181180
return Mono.from(connection.close());
182-
}).onErrorResume(NoTransactionException.class, e -> Mono.from(connection.close()));
181+
}).onErrorResume(NoTransactionException.class, ex -> Mono.from(connection.close()));
183182
}
184183

185184
/**
@@ -268,7 +267,8 @@ private static boolean connectionEquals(ConnectionHolder conHolder, Connection p
268267
Connection heldCon = conHolder.getConnection();
269268
// Explicitly check for identity too: for Connection handles that do not implement
270269
// "equals" properly).
271-
return (heldCon == passedInCon || heldCon.equals(passedInCon) || getTargetConnection(heldCon).equals(passedInCon));
270+
return (heldCon == passedInCon || heldCon.equals(passedInCon) ||
271+
getTargetConnection(heldCon).equals(passedInCon));
272272
}
273273

274274
/**

spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionContextManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -46,10 +46,10 @@ private TransactionContextManager() {
4646
* transactional context holder. Context retrieval fails with NoTransactionException
4747
* if no context or context holder is registered.
4848
* @return the current {@link TransactionContext}
49-
* @throws NoTransactionException if no TransactionContext was found in the subscriber context
50-
* or no context found in a holder
49+
* @throws NoTransactionException if no TransactionContext was found in the
50+
* subscriber context or no context found in a holder
5151
*/
52-
public static Mono<TransactionContext> currentContext() throws NoTransactionException {
52+
public static Mono<TransactionContext> currentContext() {
5353
return Mono.deferContextual(ctx -> {
5454
if (ctx.hasKey(TransactionContext.class)) {
5555
return Mono.just(ctx.get(TransactionContext.class));

spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionSynchronizationManager.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -32,8 +32,8 @@
3232

3333
/**
3434
* Central delegate that manages resources and transaction synchronizations per
35-
* subscriber context.
36-
* To be used by resource management code but not by typical application code.
35+
* subscriber context. To be used by resource management code but not by typical
36+
* application code.
3737
*
3838
* <p>Supports one resource per key without overwriting, that is, a resource needs
3939
* to be removed before a new one can be set for the same key.
@@ -73,6 +73,7 @@ public class TransactionSynchronizationManager {
7373

7474

7575
public TransactionSynchronizationManager(TransactionContext transactionContext) {
76+
Assert.notNull(transactionContext, "TransactionContext must not be null");
7677
this.transactionContext = transactionContext;
7778
}
7879

@@ -88,10 +89,11 @@ public static Mono<TransactionSynchronizationManager> forCurrentTransaction() {
8889
return TransactionContextManager.currentContext().map(TransactionSynchronizationManager::new);
8990
}
9091

92+
9193
/**
92-
* Check if there is a resource for the given key bound to the current thread.
94+
* Check if there is a resource for the given key bound to the current context.
9395
* @param key the key to check (usually the resource factory)
94-
* @return if there is a value bound to the current thread
96+
* @return if there is a value bound to the current context
9597
*/
9698
public boolean hasResource(Object key) {
9799
Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key);
@@ -100,9 +102,9 @@ public boolean hasResource(Object key) {
100102
}
101103

102104
/**
103-
* Retrieve a resource for the given key that is bound to the current thread.
105+
* Retrieve a resource for the given key that is bound to the current context.
104106
* @param key the key to check (usually the resource factory)
105-
* @return a value bound to the current thread (usually the active
107+
* @return a value bound to the current context (usually the active
106108
* resource object), or {@code null} if none
107109
*/
108110
@Nullable

spring-tx/src/test/java/org/springframework/transaction/event/TransactionalEventListenerTests.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -57,6 +57,7 @@
5757

5858
/**
5959
* Integration tests for {@link TransactionalEventListener} support
60+
* with thread-bound transactions.
6061
*
6162
* @author Stephane Nicoll
6263
* @author Sam Brannen
@@ -87,7 +88,6 @@ public void immediately() {
8788
getEventCollector().assertEvents(EventCollector.IMMEDIATELY, "test");
8889
getEventCollector().assertTotalEventsCount(1);
8990
return null;
90-
9191
});
9292
getEventCollector().assertEvents(EventCollector.IMMEDIATELY, "test");
9393
getEventCollector().assertTotalEventsCount(1);
@@ -115,7 +115,6 @@ public void afterCompletionCommit() {
115115
getContext().publishEvent("test");
116116
getEventCollector().assertNoEventReceived();
117117
return null;
118-
119118
});
120119
getEventCollector().assertEvents(EventCollector.AFTER_COMPLETION, "test");
121120
getEventCollector().assertTotalEventsCount(1); // After rollback not invoked
@@ -129,7 +128,6 @@ public void afterCompletionRollback() {
129128
getEventCollector().assertNoEventReceived();
130129
status.setRollbackOnly();
131130
return null;
132-
133131
});
134132
getEventCollector().assertEvents(EventCollector.AFTER_COMPLETION, "test");
135133
getEventCollector().assertTotalEventsCount(1); // After rollback not invoked
@@ -142,7 +140,6 @@ public void afterCommit() {
142140
getContext().publishEvent("test");
143141
getEventCollector().assertNoEventReceived();
144142
return null;
145-
146143
});
147144
getEventCollector().assertEvents(EventCollector.AFTER_COMMIT, "test");
148145
getEventCollector().assertTotalEventsCount(1); // After rollback not invoked
@@ -307,13 +304,12 @@ public void conditionFoundOnTransactionalEventListener() {
307304
}
308305

309306
@Test
310-
public void afterCommitMetaAnnotation() throws Exception {
307+
public void afterCommitMetaAnnotation() {
311308
load(AfterCommitMetaAnnotationTestListener.class);
312309
this.transactionTemplate.execute(status -> {
313310
getContext().publishEvent("test");
314311
getEventCollector().assertNoEventReceived();
315312
return null;
316-
317313
});
318314
getEventCollector().assertEvents(EventCollector.AFTER_COMMIT, "test");
319315
getEventCollector().assertTotalEventsCount(1);
@@ -326,7 +322,6 @@ public void conditionFoundOnMetaAnnotation() {
326322
getContext().publishEvent("SKIP");
327323
getEventCollector().assertNoEventReceived();
328324
return null;
329-
330325
});
331326
getEventCollector().assertNoEventReceived();
332327
}

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/MappedInterceptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -61,7 +61,7 @@
6161
*/
6262
public final class MappedInterceptor implements HandlerInterceptor {
6363

64-
private static PathMatcher defaultPathMatcher = new AntPathMatcher();
64+
private static final PathMatcher defaultPathMatcher = new AntPathMatcher();
6565

6666

6767
@Nullable

0 commit comments

Comments
 (0)