Java tutorial
public class Main { public static void main(String[] args) { MyThread t1 = new MyThread("R"); MyThread t2 = new MyThread("S"); // this will call run() method t1.start(); t2.start(); } } class MyThreadLocal extends ThreadLocal { private static int n = 10; protected Object initialValue() { return new Integer(n--); } } class MyThread extends Thread { ThreadLocal t = new MyThreadLocal(); MyThread(String name) { super(name); } public void run() { for (int i = 0; i < 2; i++) System.out.println(getName() + " " + t.get()); } }