LocaleContextHolder returns only language-code without country-code

813 Views Asked by At

I am currently using LocaleContextHolder.getLocale() to get the locale.

But the issue is, sometimes it returns language-code without country-code.

For e.g. : sometimes en_US, and sometimes en only

What could be the possible reason ?

FYI : Running Environment is : Java11, spring5.3.9.

How can I make sure that the getLocale() method should return lang-code_country-code (en_US) ?

Any help would be greatly appreciated !

Simplifying the problem statement

When using LocaleContextHolder.getLocale() within parallel stream then LocaleContextHolder.getLocale() giving different locale for child thread. For e.g. for main thread en_us and for other threads en.

contacts.parallelStream().forEach(contact -> {
Locale locale =  LocaleContextHolder.getLocale();
//some work....
});

output threads

nio-8080 : en_US, onPool-worker : en, ......, onPool-worker : en

0

There are 0 best solutions below