标题: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



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-419383-1-1.html




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

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