三个并发线程

三个并发线程

public class ThreadBasic extends Thread {
	String message;
	
	ThreadBasic (String message) {//类ThreadBasic的构造函数
		this.message=message;
	}
	
	public void run() {//实现重定义父类的run方法
//	    int sleeptime=(int)(Math.random()*3000);
//		try{
//			sleep(sleeptime);//睡眠	
//		}catch(InterruptedException e){}
		
		System.out.println(message);
	}
	
	public static void main(String[] args) {
		ThreadBasic ht1=new ThreadBasic("good");
		ThreadBasic ht2=new ThreadBasic("moringn");
		ThreadBasic ht3=new ThreadBasic("to");
		
		ht1.start();
		ht2.start();
		ht3.start();
		
		try{
			sleep(10000);
		}catch(InterruptedException e) {}
		
		System.out.println("You!");	
	}	
}

 

你可能感兴趣的:(thread)