ThreadLocal<T> and static approach?

Viewed 7865

Static fields are being accessed using the class name like this:

public class Me()
{ 
  public static int a=5;
}

I can access it with Me.a, so it is attached to the class.

But when I look at:

static ThreadLocal<int> _x = new ThreadLocal<int> (() => 3);

It guarantees that each thread sees different copy of _x.

Didn't we just see that static is per class and not per thread? How does ThreadLocal manage to give each thread a different copy of _x?

3 Answers
Related