WEB开发网
开发学院软件开发Java Java线程:深入ThreadLocal 阅读

Java线程:深入ThreadLocal

 2010-01-22 00:00:00 来源:WEB开发网   
核心提示: /***测试线程**@authorleizhimin2010-1-510:39:18*/publicclassTestThreadextendsThread{privateMyThreadLocaltlt=newMyThreadLocal();publicTestThread(MyThreadL

/** 
* 测试线程 
* 
* @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(); 
        } 
}

上一页  1 2 3 4 5 6 7  下一页

Tags:Java 线程 深入

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接