1. 程式人生 > >畫坦克__線程__V2__第二種方式調用

畫坦克__線程__V2__第二種方式調用

out cat == 線程 art str exception cnblogs ini

一、代碼如下

package www.tainiu.gui__V2;

import java.util.Random;

public class aa__XianCheng__V2 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Dog dog1= new Dog();
		Thread t1= new Thread(dog1);
		Thread t2= new Thread(dog1);
		t1.start();
		t2.start();

	}

}

class Dog implements Runnable{
    int times= 0;
	@Override
	public void run() {
		// TODO Auto-generated method stub
		while(true) {
			try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}
			times ++;
			System.out.println("Hello World__"+times);
			if(times == 10 || times==17) {
				break;
			}
		}
		
	}
	
}

畫坦克__線程__V2__第二種方式調用