线程中Join的使用例子

时间:2023-12-04 10:55:38

1.实现Runnbale接口,

package 网易若干java;
//这个例子共有2个线程,一个是主线程,一个是线程t public class MyThread1 implements Runnable{ public static void main(String args[]) throws InterruptedException
{
Thread t=new Thread(new MyThread1());
t.start();
System.out.println("rm1");
t.join(); //主线程等待线程t结束
System.out.println("rm2"); } @Override
public void run() {
// TODO Auto-generated method stub
System.out.println("r1");
System.out.println("r2"); } }