Attempt<V> attempt; try { V result = attemptTimeLimiter.call(callable); attempt = new ResultAttempt<V>(result, attemptNumber, TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime)); } catch (Throwable t) {
@Test public void testFixedTimeLimitWithNoExecutorReusesThreads() throws Exception { Set<Long> threadsUsed = Collections.synchronizedSet(Sets.newHashSet()); Callable<Void> callable = () -> { threadsUsed.add(Thread.currentThread().getId()); return null; }; int iterations = 20; for (int i = 0; i < iterations; i++) { AttemptTimeLimiter timeLimiter = AttemptTimeLimiters.fixedTimeLimit(1, TimeUnit.SECONDS); timeLimiter.call(callable); } assertTrue("Should have used less than " + iterations + " threads", threadsUsed.size() < iterations); }
Attempt<T> attempt; try { T result = attemptTimeLimiter.call(callable); attempt = new Attempt<>(result, attemptNumber, System.currentTimeMillis() - startTimeMillis); } catch(InterruptedException e) {