标签:
/*
需求:
写一个简单的线程测试,采用实现的Runnable的run()
打印一句句简单自定义线程名字的语句Thread World Wecome You!!
和默认的线程名字的语句:This is defalut ThreadName:默认的线程名字
*/
class TEST_Thread implements Runnable{
private String name;
public void getName(String name){
this.name=name;
}
public void show(Object obj){
System.out.println(obj);
}
public void run(){
if(name=="小明")
show(name+":Runnable World Wecome You!!");
else
show("This is defalut ThreadName:"+Thread.currentThread().getName());
}
}
public class Runnabletest{
public static void main(String args[]){
//创建线程对象
TEST_Thread TT=new TEST_Thread();
TEST_Thread TT2=new TEST_Thread();
//将线程对象封装到Thread中
Thread t1=new Thread(TT);
Thread t2=new Thread(TT2);
TT2.getName("小明");
//启动start();
t1.start();
t2.start();
}
}
/*
打印结果:
This is defalut ThreadName:Thread-0
小明:Thread World Wecome You!!
*/
标签:
原文地址:http://www.cnblogs.com/heji/p/5925662.html