zoukankan      html  css  js  c++  java
  • JUC之---超好用的阻塞锁

    1、LockSupport:用这个锁来实现线程阻塞与释放,不要太好用

    2、上demo:

      

    public class T_LockSupport {

    public static void main(String[] args) {

    Thread thread = new Thread(()->{
    for (int i = 0; i < 10; i++) {
    System.out.println(i);
    if (i == 5) {
    LockSupport.park(); //在这里阻塞住
    }
    try {
    TimeUnit.SECONDS.sleep(1);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }

    }
    });

    thread.start();

    //主线程阻塞10秒以后,使得thread线程继续执行
    try {
    TimeUnit.SECONDS.sleep(10);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }

    LockSupport.unpark(thread);

    }

    }
  • 相关阅读:
    go
    go
    go
    postgresql
    go
    go
    sql
    铂金软件公司
    HRIS 的价值评估
    [转]数据库SQL优化大总结之 百万级数据库优化方案
  • 原文地址:https://www.cnblogs.com/tengri-fighting/p/12764557.html
Copyright © 2011-2022 走看看