Merge pull request #32874 from Seungpang

* pr/32874:
  Polish
  Document using ThreadLocal#remove instead of ThreadLocal#set(null)

Closes gh-32874
This commit is contained in:
Stéphane Nicoll 2024-05-23 08:14:00 +02:00
commit 31f298b929
2 changed files with 3 additions and 3 deletions

View File

@ -221,8 +221,8 @@ NOTE: `ThreadLocal` instances come with serious issues (potentially resulting in
incorrectly using them in multi-threaded and multi-classloader environments. You incorrectly using them in multi-threaded and multi-classloader environments. You
should always consider wrapping a `ThreadLocal` in some other class and never directly use should always consider wrapping a `ThreadLocal` in some other class and never directly use
the `ThreadLocal` itself (except in the wrapper class). Also, you should the `ThreadLocal` itself (except in the wrapper class). Also, you should
always remember to correctly set and unset (where the latter simply involves a call to always remember to correctly set and unset (where the latter involves a call to
`ThreadLocal.set(null)`) the resource local to the thread. Unsetting should be done in `ThreadLocal.remove()`) the resource local to the thread. Unsetting should be done in
any case, since not unsetting it might result in problematic behavior. Spring's any case, since not unsetting it might result in problematic behavior. Spring's
`ThreadLocal` support does this for you and should always be considered in favor of using `ThreadLocal` support does this for you and should always be considered in favor of using
`ThreadLocal` instances without other proper handling code. `ThreadLocal` instances without other proper handling code.

View File

@ -135,7 +135,7 @@ class AbstractRoutingDataSourceTests {
routingDataSource.setDefaultTargetDataSource(ds); routingDataSource.setDefaultTargetDataSource(ds);
routingDataSource.setLenientFallback(false); routingDataSource.setLenientFallback(false);
routingDataSource.afterPropertiesSet(); routingDataSource.afterPropertiesSet();
lookupKey.set(null); lookupKey.remove();
assertThat(routingDataSource.determineTargetDataSource()).isSameAs(ds); assertThat(routingDataSource.determineTargetDataSource()).isSameAs(ds);
} }