package com.atguigu.javademo.juc;
import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.LockSupport;
public class JUCDEmo2 { public static void main(String[] args) { Thread mainThread = Thread.currentThread() ; System.out.println(“主线程等待”); new Thread(()->{ try{ System.err.println(“子线程执行。。。”); TimeUnit.SECONDS.sleep(3); System.err.println(“子线程执行完。。。”); } catch (InterruptedException e) { e.printStackTrace(); } finally { LockSupport.unpark(mainThread);//解锁主线程 } }).start(); LockSupport.park();//主线程暂停,等待 System.out.println(“主线程再执行”); } }
|