Category «Java»

Using ThreadLocal to access variables for each thread

If you would like to keep your variables’ values separate from different threads and would also like to access the variables without having to pass them as parameters then a good way would be to use the ThreadLocal. ThreadLocal is used for thread-local variables. Here is an example on how to use it. Create the …