I have some spring-boot
application (it exposes rest api). The mentioned REST API
is secured by spring-security
. Everything is fine, however now I need
If you use only one thread in your program, the answer is yes. There are no reasons run this operations in different threads, because switching threads is overhead. But in your program you or somebody can define async operations (@Async, Thread.start(), events, etc.) in that case there are more then one thread, and your ThreadLocal will handle value only for the first thread.
Yes, but see first paragraph.
I recommend for this task use thread safe cache (for example ConcurrentHashMap) associate with users. It will be simpler for understanding and thread safe. If you want use ThreadLocal you need to clarify and minimize his lifecycle in your application.