Jack_King007的专栏

java之多线程实例

这个题目主要联系多线程的模板代码和 Thread.sleep的使用

package ThreadTest;
class Work implements Runnable{
 private String name;
 private int time;
 
	public Work(String name, int time) {
	super();
	this.name = name;
	this.time = time;
}

	public void run() {
		try {
			Thread.sleep(this.time);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(this.name+"线程,休眠"+this.time+"毫秒");
		
	}
	
}
public class WorkTest {
public static void main(String[] args) {
	Work work=new Work("线程A", 5000);
	Work work1=new Work("线程B", 4000);
	Work work2=new Work("线程C", 3000);
	new Thread(work).start();
	new Thread(work1).start();
	new Thread(work2).start();
}
}