码上敲享录 > java高并发常见问题 > Semaphore的acquireUninterruptibly()的作用和使用

Semaphore的acquireUninterruptibly()的作用和使用

上一章章节目录下一章 2018-08-01已有3751人阅读 评论(0)

Semaphore的acquireUninterruptibly()的作用和使用

答:

方法acquireUninterruptibly()的作用是使等待进入acquire()方法的线程,不允许被中断。

private Semaphore semaphore = new Semaphore(1);
public void testMethod() {
try {
semaphore.acquireUninterruptibly();
System.out.println(Thread.currentThread().getName() + "执行时间=" + System.currentTimeMillis());
semaphore.release();
} catch (Exception e) {
       e.printStackTrace()
;
}
}

本文链接:http://www.yayihouse.com/yayishuwu/chapter/1392

向大家推荐《Activiti工作流实战教程》:https://xiaozhuanlan.com/activiti
0

有建议,请留言!

  • *您的姓名:

  • *所在城市:

  • *您的联系电话:

    *您的QQ:

  • 咨询问题:

  • 提 交