画坦克__线程__V2__第二种方式调用

 

一、代码如下

 

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;
			}
		}
		
	}
	
}

 

posted @ 2017-10-06 22:13  18513757531  阅读(99)  评论(0编辑  收藏  举报