Java TimeUnit Usage getWithTimeout(final Future future)

Here you can find the source of getWithTimeout(final Future future)

Description

Calls Future#get(long,TimeUnit) with TestUtils#TIMEOUT in seconds.

License

Open Source License

Parameter

Parameter Description
future future
T type

Exception

Parameter Description
Exception exception

Return

future result

Declaration

static <T> T getWithTimeout(final Future<T> future) throws Exception 

Method Source Code


//package com.java2s;
/*/*  w w w.ja  va2s.co  m*/
 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

public class Main {
    private static final long TIMEOUT = 3;

    /**
     * Calls {@link Future#get(long, TimeUnit)} with {@link TestUtils#TIMEOUT} in seconds.
     *
     * @param future future
     * @param <T>    type
     * @return future result
     * @throws Exception exception
     */
    static <T> T getWithTimeout(final Future<T> future) throws Exception {
        return future.get(TIMEOUT, TimeUnit.SECONDS);
    }
}

Related

  1. getTimeString(long millis)
  2. getTimezoneOffset(TimeZone timeZone)
  3. getTomorrowTimestamp()
  4. getUnit(long nanos)
  5. getValidityAsString(Date endDate)
  6. humanizeTime(long hours, long minutes, long seconds)
  7. humanizeToTime(long millis)
  8. humanReadableDuration(Date from, Date to)
  9. humanReadableMillis(long millis)