<李兴华视频笔记>
//线程A休眠10秒
//线程B休眠20秒
//线程C休眠30秒
class MyThread implements Runnable
{
private String name ;
private int time ;
public MyThread(String name,int time){
this.name = name ;
this.time = time ;
}
public void run(){
try{
Thread.sleep(time) ;
}catch(Exception e){
e.printStackTrace() ;
}
System.out.println(this.name+"线程,休眠"+this.time+"毫秒") ;
}
}
public class ExecDemo02
{
public static void main(String args[]){
MyThread mt1 = new MyThread("线程A",10000) ;
MyThread mt2 = new MyThread("线程B",20000) ;
MyThread mt3 = new MyThread("线程C",30000) ;
new Thread(mt1).start();
new Thread(mt2).start();
new Thread(mt3).start();
}
}
//线程A休眠10秒
//线程B休眠20秒
//线程C休眠30秒
class MyThread extends Thread
{
private int time ;
public MyThread(String name,int time){
super(name) ;
this.time = time ;
}
public void run(){
try{
Thread.sleep(time) ;
}catch(Exception e){
e.printStackTrace() ;
}
System.out.println(Thread.currentThread().getName()+"线程,休眠"+this.time+"毫秒") ;
}
}
public class ExecDemo01
{
public static void main(String args[]){
MyThread mt1 = new MyThread("线程A",10000) ;
MyThread mt2 = new MyThread("线程B",20000) ;
MyThread mt3 = new MyThread("线程C",30000) ;
mt1.start();
mt2.start();
mt3.start();
}
}