class MyThread extends Thread { // 线程的主体类 private String title; public MyThread(String title) { this.title = title; } @Override public void run() { // 线程的主方法 for (int x = 0; x < 50; x++) { System.out.println(this.title + "运行,x = " + x); } } } |
public class TestDemo { public static void main(String[] args) throws Exception { MyThread mt1 = new MyThread("线程A") ; MyThread mt2 = new MyThread("线程B") ; MyThread mt3 = new MyThread("线程C") ; mt1.run() ; mt2.run() ; mt3.run() ; } } |
public class TestDemo { public static void main(String[] args) throws Exception { MyThread mt1 = new MyThread("线程A") ; MyThread mt2 = new MyThread("线程B") ; MyThread mt3 = new MyThread("线程C") ; mt1.start() ; mt2.start() ; mt3.start() ; } } |
public synchronized void start() { if (threadStatus != 0) throw new IllegalThreadStateException(); group.add(this); boolean started = false; try { start0(); started = true; } finally { try { if (!started) { group.threadStartFailed(this); } } catch (Throwable ignore) { } } } private native void start0(); |
java.lang.Object |- java.lang.Throwable |- java.lang.Exception |- java.lang.RuntimeException |- java.lang.IllegalArgumentException |- java.lang.IllegalThreadStateException |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |