class MyThread extends Thread{
//¾U¿ç¨‹å»¶è¿Ÿæ—‰™—´
private int time;
//¾U¿ç¨‹çš„åå—ç”±Thread累自行管ç?br />
public MyThread(String name,int time){
//调用Thread¾cÖM¸çš„æž„é€ æ–¹æ³•ï¼Œè®„¡½®¾U¿ç¨‹çš„åå?br />
super(name);
this.time=time;
}
public void run(){
for(int i=0;i<10;i++){
try {
Thread.sleep(this.time);
} catch (InterruptedException e) {
e.printStackTrace();
}
this.printMsg();
}
}
public void printMsg(){
System.out.println (Thread.currentThread().getName()+"-->***æ£åœ¨˜q行***"+this.time+"¿U?);
}
}
public class Demo {
public static void main(String[] args){
MyThread mt = new MyThread("AA",100);
MyThread mt1 = new MyThread("BB",200);
MyThread mt2 = new MyThread("CC",300);
mt.start();
mt1.start();
mt2.start();
}
}
class MyThread1 implements Runnable{
private String name;
private int time;
public MyThread1(String name,int time){
this.name= name;
this.time=time;
}
public void run(){
for(int i=0;i<10;i++){
try {
Thread.sleep(this.time);
} catch (InterruptedException e) {
e.printStackTrace();
}
this.printMsg();
}
}
public void printMsg(){
System.out.println (this.name+"-->***æ£åœ¨˜q行***"+this.time+"¿U?);
}
}
public class DemoF {
public static void main(String[] args){
MyThread mt = new MyThread("AA",100);
MyThread mt1 = new MyThread("BB",200);
MyThread mt2 = new MyThread("CC",300);
mt.start();
mt1.start();
mt2.start();
}
}
˜q行¾l“æžœåQšç±»åŒäºŽä¸Šä¸€¿U方法的¾l“æžœåQŒåªæ˜¯å‡ºçš„顺åºä¸ç›¸åŒ