`

简单的多线程案例

 
阅读更多
例一:
public class Test extends Thread{

public void run(){

try {

Thread.sleep(1000*5);

} catch (InterruptedException e) {


e.printStackTrace();

}

System.out.println("101");

}

}

public class Maintest {

public static void main(String[] args) {

System.out.println(102);

Test test=new Test();

test.start();

System.out.println(103);

}

}

//输出结果为102  103  101

 
例二:
public class Test extends Thread{

public void run(){

System.out.println("101");

}

public class Maintest {

public static void main(String[] args) {

System.out.println(102);

Test test=new Test();

test.sleep(1000*10);//阻塞当前线程

test.start();

System.out.println(103);

}

}

//输出结果:102  101  103
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics