/** * Acquires a permit from this semaphore, if one becomes available within the given waiting time * and the current thread has not been {@link Thread#interrupt interrupted}. * * @param timeout the maximum time to wait for a permit * @return <tt>true</tt> if a permit was acquired and <tt>false</tt> if the waiting time elapsed * before a permit was acquired. * @throws InterruptedException if the current thread is interrupted * @see Thread#interrupt */ public boolean tryAcquire(long timeout) throws InterruptedException { return tryAcquire(1, timeout); }
/** * Acquires a permit from this semaphore, if one becomes available within the given waiting time * and the current thread has not been {@link Thread#interrupt interrupted}. * * @param timeout the maximum time to wait for a permit * @return <tt>true</tt> if a permit was acquired and <tt>false</tt> if the waiting time elapsed * before a permit was acquired. * @throws InterruptedException if the current thread is interrupted * @see Thread#interrupt */ public boolean tryAcquire(long timeout) throws InterruptedException { return tryAcquire(1, timeout); }
public static void waitForEvent(int occurrences, String event, long timeout) { boolean debug = log.isDebugEnabled(); if (debug) log.debug("waiting for " + event); Semaphore eventSemaphore = getEventSemaphore(event); try { if (!eventSemaphore.tryAcquire(occurrences, timeout)) { throw new JbpmException("event '" + event + "' did not occur within " + timeout + " ms"); } if (debug) log.debug("received '" + event + "' notification"); } catch (InterruptedException e) { throw new JbpmException("wait for event '" + event + "' was interrupted", e); } }
public static void waitForEvent(int occurrences, String event, long timeout) { boolean debug = log.isDebugEnabled(); if (debug) log.debug("waiting for " + event); Semaphore eventSemaphore = getEventSemaphore(event); try { if (!eventSemaphore.tryAcquire(occurrences, timeout)) { throw new JbpmException("event '" + event + "' did not occur within " + timeout + " ms"); } if (debug) log.debug("received '" + event + "' notification"); } catch (InterruptedException e) { throw new JbpmException("wait for event '" + event + "' was interrupted", e); } }