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();
}
}