스레드 예제【2】

745 단어 thread
package com.thread;
/**
 * 2010-10-26
 *   Thread    
 *     hello world,   10      
 * @author Administrator
 *
 */
public class Demo2 {

	public static void main(String args[]){
		Dog dog=new Dog();
		dog.start();
	}
}

class Dog extends Thread{
	
	public void run(){
		int time=0;
		while(true){
			
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("hello,world");
			time++;
			if(time==10){
				//  ,  while  ,      
				break;
			}
		}
	}
}

좋은 웹페이지 즐겨찾기