设置线程名

class MyThread implements Runnable
{
    public void run()
    {
        for (int i=0;i<100;i++)
        {
            this.printMsg();
        }
    }
    public void printMsg()
    {
        System.out.println(Thread.currentThread().getName()+"在运行.....");
    }
}


public class debug {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        MyThread mt=new MyThread();
        Thread t =new Thread(mt);
        t.setName("线程A");
        t.start();
        for (int i=0;i<100;i++)
        {
            mt.printMsg();
        }        
    }        
}

 

posted @ 2013-11-08 15:09  glt66  阅读(157)  评论(0编辑  收藏  举报