In a singleton class , am having private static ThreadLocal variable. Whether that variable will be shared among users accessing that singleton class , Or won't be shared ?
Each thread that accesses the variable of singleton class object (via its get or set method) has its own, independently initialized copy of that variable, it woun't be shared and that is the character of ThreadLocal variable.
Documentation
ThreadLocal is different. SingleTon is different.
ThreadLocal
Even singleton object has different thread local in different thread.
For ex,
A is a singleton reference. A can be shared in multiple threads. So each thread has thread specific thread local value.
Singleton
Only one object exists in JVM at a time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With