This class provides thread-local variables. These variables differ from their normal counterparts in that each thread that accesses one (via its get or set method) has its own, independently initialized copy of the variable. ThreadLocal instances are typically private static fields in classes that wish to associate state with a thread (e.g., a user ID or Transaction ID).
This class allows you to put local data on a thread, so that every module running in the thread can access it
public class MyService {
private static ThreadLocal tLocal = new ThreadLocal();
public static void set(List list) {
tLocal.set(list);
}
public static List get() {
return (List) tLocal.get();
}
Client:
MyService.set(list);
.......
list = MyService.get();
No comments:
Post a Comment