@Override public Predicate<Void> get() { return new TimeToLive(getNanosTimeout(time, unit)); } });
/** * Version of {@link #invokeAll(Iterable)} that supports a timeout. Any jobs * that are not complete by the timeout are interrupted and discarded. * * @param <T> the result type * @param callables the jobs to run * @param time the max time spent per job specified by: * @param unit the TimeUnit time is specified in * @return an Iterable that returns the results in the order in which they * return, excluding any null values. * * @see #invokeAll(Iterable) * @since 2.1 */ public <T> Iterable<T> invokeAll(final Iterable<? extends Callable<T>> callables, final long time, final TimeUnit unit) { return invokeAllTasks(callables, new TimeoutAccessor<T>(getNanosTimeout(time, unit))); }
final Timeout timeout = Timeout.getNanosTimeout(time, unit); V result = null; while (result == null) {
/** * Gets the current element if it is not null, if it is null then this method * blocks and waits until it is not null. Unlike {@link #take()} it does not * reset the current element to null. * <p> * If the current thread: * <ul> * <li>has its interrupted status set on entry to this method; or * <li>is {@link Thread#interrupt() interrupted} while waiting, * </ul> * then {@link InterruptedException} is thrown and the current thread's * interrupted status is cleared. * * @return the current element * @throws TimeoutException if the timeout is reached without another thread * having called {@link #set(Object)}. * @throws InterruptedException if the current thread is interrupted while * waiting */ @NotNull public V get(final long time, @NotNull final TimeUnit unit) throws TimeoutException, InterruptedException { final Timeout timeout = Timeout.getNanosTimeout(time, unit); V result = ref.get(); while (result == null) { timeout.await(latch); result = ref.get(); } return result; }
public boolean await(final long time, final TimeUnit unit) { final Timeout timeout = Timeout.getNanosTimeout(time, unit); try { return future.get(timeout.getTime(), timeout.getUnit()).await(timeout.getTime(), timeout.getUnit()); } catch (final ExecutionException e) { throw new RuntimeException(e); } catch (final TimeoutException e) { return false; } catch (final InterruptedException e) { throw new RuntimeInterruptedException(e); } }
public boolean await(final long time, final TimeUnit unit) final Timeout timeout = Timeout.getNanosTimeout(time, unit); for (final Iterator<InFlightResult> it = results.iterator(); it.hasNext();)