/** * Tries to acquire a permit from this semaphore. If the limit of this semaphore has * not yet been reached, a permit is acquired, and this method returns * <strong>true</strong>. Otherwise, this method returns immediately with the result * <strong>false</strong>. * * @return <strong>true</strong> if a permit could be acquired; <strong>false</strong> * otherwise * @throws IllegalStateException if this semaphore is already shut down * @since 3.5 */ public synchronized boolean tryAcquire() { prepareAcquire(); return acquirePermit(); }
/** * Acquires a permit from this semaphore. This method will block if * the limit for the current period has already been reached. If * {@link #shutdown()} has already been invoked, calling this method will * cause an exception. The very first call of this method starts the timer * task which monitors the time period set for this {@code TimedSemaphore}. * From now on the semaphore is active. * * @throws InterruptedException if the thread gets interrupted * @throws IllegalStateException if this semaphore is already shut down */ public synchronized void acquire() throws InterruptedException { prepareAcquire(); boolean canPass; do { canPass = acquirePermit(); if (!canPass) { wait(); } } while (!canPass); }
/** * Tries to acquire a permit from this semaphore. If the limit of this semaphore has * not yet been reached, a permit is acquired, and this method returns * <strong>true</strong>. Otherwise, this method returns immediately with the result * <strong>false</strong>. * * @return <strong>true</strong> if a permit could be acquired; <strong>false</strong> * otherwise * @throws IllegalStateException if this semaphore is already shut down * @since 3.5 */ public synchronized boolean tryAcquire() { prepareAcquire(); return acquirePermit(); }
/** * Tries to acquire a permit from this semaphore. If the limit of this semaphore has * not yet been reached, a permit is acquired, and this method returns * <strong>true</strong>. Otherwise, this method returns immediately with the result * <strong>false</strong>. * * @return <strong>true</strong> if a permit could be acquired; <strong>false</strong> * otherwise * @throws IllegalStateException if this semaphore is already shut down * @since 3.5 */ public synchronized boolean tryAcquire() { prepareAcquire(); return acquirePermit(); }
/** * Tries to acquire a permit from this semaphore. If the limit of this semaphore has * not yet been reached, a permit is acquired, and this method returns * <strong>true</strong>. Otherwise, this method returns immediately with the result * <strong>false</strong>. * * @return <strong>true</strong> if a permit could be acquired; <strong>false</strong> * otherwise * @throws IllegalStateException if this semaphore is already shut down * @since 3.5 */ public synchronized boolean tryAcquire() { prepareAcquire(); return acquirePermit(); }
/** * Acquires a permit from this semaphore. This method will block if * the limit for the current period has already been reached. If * {@link #shutdown()} has already been invoked, calling this method will * cause an exception. The very first call of this method starts the timer * task which monitors the time period set for this {@code TimedSemaphore}. * From now on the semaphore is active. * * @throws InterruptedException if the thread gets interrupted * @throws IllegalStateException if this semaphore is already shut down */ public synchronized void acquire() throws InterruptedException { prepareAcquire(); boolean canPass; do { canPass = acquirePermit(); if (!canPass) { wait(); } } while (!canPass); }
/** * Acquires a permit from this semaphore. This method will block if * the limit for the current period has already been reached. If * {@link #shutdown()} has already been invoked, calling this method will * cause an exception. The very first call of this method starts the timer * task which monitors the time period set for this {@code TimedSemaphore}. * From now on the semaphore is active. * * @throws InterruptedException if the thread gets interrupted * @throws IllegalStateException if this semaphore is already shut down */ public synchronized void acquire() throws InterruptedException { prepareAcquire(); boolean canPass; do { canPass = acquirePermit(); if (!canPass) { wait(); } } while (!canPass); }
/** * Acquires a permit from this semaphore. This method will block if * the limit for the current period has already been reached. If * {@link #shutdown()} has already been invoked, calling this method will * cause an exception. The very first call of this method starts the timer * task which monitors the time period set for this {@code TimedSemaphore}. * From now on the semaphore is active. * * @throws InterruptedException if the thread gets interrupted * @throws IllegalStateException if this semaphore is already shut down */ public synchronized void acquire() throws InterruptedException { prepareAcquire(); boolean canPass; do { canPass = acquirePermit(); if (!canPass) { wait(); } } while (!canPass); }