Java创建线程的两种方式
public static void main(String[] args) throws InterruptedException {
Thread thread1 = new Thread1();
Thread2 thread2 = new Thread2();
Thread thread3 = new Thread(thread2, "线程名称");
thread1.start();
thread3.start();
}
static class Thread1 extends Thread {
@Override
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("线程一" + i);
}
}
}
static class Thread2 implements Runnable {
@Override
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("线程二" + i);
}
}
}