线程系列三

public class TestThread2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Runner2 r = new Runner2();
		r.start();
		
		for(int i=0; i<10; i++) {
			System.out.println("Main Thread :" + i);
		}
	}

}


class Runner2 extends Thread {

	@Override
	public void run() {
		// TODO Auto-generated method stub
		
		for(int i=0; i<10; i++) {
			System.out.println("Runner2 :" + i);
		}
	}
	
}



运行结果:

Runner2 :0
Main Thread :0
Runner2 :1
Main Thread :1
Main Thread :2
Runner2 :2
Main Thread :3
Runner2 :3
Main Thread :4
Runner2 :4
Main Thread :5
Runner2 :5
Runner2 :6
Runner2 :7
Main Thread :6
Main Thread :7
Runner2 :8
Runner2 :9
Main Thread :8
Main Thread :9



这是启动线程的第二种办法,系列二是启动线程的第一种办法。

你可能感兴趣的:(线程系列三)