| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1111 人关注过本帖
标题:Thread t = Thread.currentThread();是什么意思??
取消只看楼主 加入收藏
初学者5
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2013-8-9
结帖率:75%
收藏
 问题点数:0 回复次数:0 
Thread t = Thread.currentThread();是什么意思??
public class TwoThread extends Thread {
    private Thread creatorThread;

    public TwoThread() {
        // make a note of the thread that constructed me!
        creatorThread =Thread.currentThread();
    }

    public void run() {
        for ( int i = 0; i < 10; i++ ) {
            printMsg();
        }
    }

    public void printMsg() {
        // get a reference to the thread running this
        Thread t = Thread.currentThread();

        if ( t == creatorThread ) {
            System.out.println("Creator thread");
        } else if ( t == this ) {
            System.out.println("New thread");
        } else {
            System.out.println("Mystery thread --unexpected!");
        }
    }

    public static void main(String[] args) {
        TwoThread tt = new TwoThread();
        tt.start();

        for ( int i = 0; i < 10; i++ ) {
            tt.printMsg();
        }
    }
}
程序中的creatorThread = Thread.currentThread();和Thread t = Thread.currentThread();是什么意思???
搜索更多相关主题的帖子: reference running private thread public 
2013-08-20 08:31
快速回复:Thread t = Thread.currentThread();是什么意思??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020885 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved