/** * Attempts to acquire in shared mode, aborting if interrupted, and failing if * the given timeout elapses. Implemented by first checking interrupt status, * then invoking at least once {@link #tryAcquireShared}, returning on * success. Otherwise, the thread is queued, possibly repeatedly blocking and * unblocking, invoking {@link #tryAcquireShared} until success or the thread * is interrupted or the timeout elapses. * * @param arg * the acquire argument. This value is conveyed to * {@link #tryAcquireShared} but is otherwise uninterpreted and can * represent anything you like. * @param nanosTimeout * the maximum number of nanoseconds to wait * @return {@code true} if acquired; {@code false} if timed out * @throws InterruptedException * if the current thread is interrupted */ public final boolean tryAcquireSharedNanos(int arg, Object id, long nanosTimeout) throws InterruptedException { if (Thread.interrupted()) throw new InterruptedException(); return tryAcquireShared(arg, id) >= 0 || doAcquireSharedNanos(arg, id, nanosTimeout); }