Details
Description
The current LocaleContextHolder uses ThreadLocal to store the locale which works fine if you keep your execution to that thread. However in a multithreaded environment, the ThreadLocal value is not available when a new thread is started from that original thread.
Consider the following flow:
- in Spring MVC a GET request is being processed with 'Accept-Language' = 'nl'
- Controller that handles the GET request can read the value using LocaleContextHolder.getLocale().getLanguage()
- Controller processes some actions in parallel using multiple threads Thread A, Thread B
- When calling LocaleContextHolder.getLocale().getLanguage() from Thread A and B, the value 'nl' is not available.
In Spring Security this is already taken care of using org.springframework.security.core.context.InheritableThreadLocalSecurityContextHolderStrategy. The LocaleContextHolder should be coded in a similar way in order to switch threads and have the original value in the child thread.