下面是两种方式的多线程
package xiancheng;
//方法一
/*public class xiancheng extends Thread {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println(this.getName());
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Thread.currentThread().setName("hello");
System.out.println(Thread.currentThread().getName());
xiancheng thread1 = new xiancheng();
xiancheng thread2 = new xiancheng();
thread1.start();
thread2.start();
}
}*/
//方法二
/*
public class xiancheng implements Runnable{
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println(Thread.currentThread().getName());
}
public static void main(String[] args) {
xiancheng r1 = new xiancheng();
xiancheng r2 = new xiancheng();
xiancheng r3 = new xiancheng();
Thread thread1 = new Thread(r1);
Thread thread2 = new Thread(r2);
Thread thread3 = new Thread(r3);
thread1.start();
thread2.start();
thread3.start();
}
}*/