* Thread类:
* public Thread(String name):设置指定的线程名臣
* public Thread()
* Thread类中相关设置线程名称/获取线程名称的方法:
* public final void setName(String name):设置线程名称
* public final String getName():获取线程名称
public class ThreadDemo {
public static void main(String[] args) {
//创建两个线程对象
MyThread t1=new MyThread();
MyThread t2=new MyThread();
//设置线程名程
t1.setName("hello");
t2.setName("world");
//启动线程
t1.start();//JVM执行线程类重写的run方法
t2.start();
}
}
//自定义的线程类
//多线程方式1:
public class MyThread extends Thread{
@Override
public void run() {
for(int x=0;x<500;x++) {
System.out.println(this.getName()+" "+x);
}
}
}