Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-17604

LocaleContextHolder should have a strategy similar to SecurityContextHolder for child Thread

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Works as Designed
    • Affects Version/s: 5.1.3
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
    • Last commented by a User:
      true

      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:

      1. in Spring MVC a GET request is being processed with 'Accept-Language' = 'nl'
      2. Controller that handles the GET request can read the value using LocaleContextHolder.getLocale().getLanguage()
      3. Controller processes some actions in parallel using multiple threads Thread A, Thread B
      4. 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.

        Attachments

          Activity

            People

            Assignee:
            juergen.hoeller Juergen Hoeller
            Reporter:
            tfreyne Timothy Freyne
            Last updater:
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Days since last comment:
              3 years, 29 weeks, 6 days ago