/*
join:
当A线程执行到了B线程的.join()方法时,A就会等待。等B线程都执行完,A才会执行。
join可以用来临时加入线程执行。
*/ class Demo implements Runnable { public void run() { for(int x=0; x<70; x++) { System.out.println(Thread.currentThread().toString()+"....."+x); Thread.yield();//线程执行到这句话时候会释放执行权,线程就会相互交替运行。 } } } class JoinDemo { public static void main(String[] args) throws Exception { Demo d = new Demo(); Thread t1 = new Thread(d); Thread t2 = new Thread(d); t1.start(); //t1.setPriority(Thread.MAX_PRIORITY); t2.start(); //t1.join(); for(int x=0; x<80; x++) { //System.out.println("main....."+x); } System.out.println("over"); } }
本文地址:https://blog.csdn.net/weixin_45246666/article/details/107881541
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!
网友评论