Java线程:深入ThreadLocal
2010-01-22 00:00:00 来源:WEB开发网/**
* 测试线程
*
* @author leizhimin 2010-1-5 10:39:18
*/
public class TestThread extends Thread {
private MyThreadLocal tlt = new MyThreadLocal();
public TestThread(MyThreadLocal tlt) {
this.tlt = tlt;
}
@Override
public void run() {
for (int i = 0; i < 3; i++) {
System.out.println(Thread.currentThread().getName() + "\t" + tlt.getNextNum());
}
}
}
/**
* ThreadLocal测试
*
* @author leizhimin 2010-1-5 10:43:48
*/
public class Test {
public static void main(String[] args) {
MyThreadLocal tlt = new MyThreadLocal();
Thread t1 = new TestThread(tlt);
Thread t2 = new TestThread(tlt);
Thread t3 = new TestThread(tlt);
Thread t4 = new TestThread(tlt);
t1.start();
t2.start();
t3.start();
t4.start();
}
}
更多精彩
赞助商链接