多个线程同时执行,每个线程分别打印出自己的名字

来源:互联网 发布:java截屏网页 编辑:程序博客网 时间:2024/05/21 10:21
public class ThreadName extends Thread{

public void run()
{
System.out.println("线程:"+this.getName());//打印线程名字
}


public static void main(String[] args) {
// TODO Auto-generated method stub
ThreadName thread1=new ThreadName();//创建线程
ThreadName thread2=new ThreadName();
ThreadName thread3=new ThreadName();
thread1.setName("1号");//设置线程名字
thread2.setName("2号");
thread3.setName("3号");
thread1.start();//执行线程
thread2.start();
thread3.start();
}


}
阅读全文
0 0