java Concurrent Programming Practice
java Concurrent Programming Practice
Programmer interview
2020-04-05 11:08:16
77
Category column:
java concurrency
Article label:
ThreadLocal
...
Added by smoothrider on Fri, 18 Feb 2022 12:33:42 +0200
Interview Literacy Series: ThreadLocal principle
How to use it?
ThreadLocal<String> localName = new ThreadLocal();
localName.set("xx");
String name = localName.get();
principle
public class ThreadLocal<T> {
public void set(T value) {
Thread t = Thread.currentThread();
ThreadLocalMap map = getMap(t);
if (map != null)
map.set(this, value);
else
createMap(t, value); ...
Added by lauxanh on Sat, 29 Jan 2022 00:52:18 +0200
The best ThreadLocal posture for programmers
1, Common scenarios
1. ThreadLocal is a copy of thread context. One of the most common ways to use ThreadLocal is to implicitly pass parameters to different methods by providing two public methods: set() and get(). For programming specifications, the number of parameters is limited when defining methods. Even in some large factories, the numbe ...
Added by tommyda on Wed, 19 Jan 2022 08:56:15 +0200