Code example for TimeoutException

0
    } 
 
    public String getResult(long time, TimeUnit timeUnit) throws InterruptedException, TimeoutException {
        boolean timeoutOccurred = !latch.get().await(time, timeUnit);
        if (timeoutOccurred) {
            throw new TimeoutException("Did not get result in " + time + " " + timeUnit);
        } 
        return result.get();
 
    } 
}