Java Utililty Methods Thread Future

List of utility methods to do Thread Future

Description

The list of methods to do Thread Future are organized into topic(s).

Method

FutureCallbackcallback(final CountDownLatch latch)
callback
return new FutureCallback<V>() {
    @Override
    public void onSuccess(final V result) {
        latch.countDown();
    @Override
    public void onFailure(final Throwable t) {
        latch.countDown();
...
booleancancel(final Future future)
cancel
return future.isDone() || future.isCancelled() || future.cancel(true);
booleancancel(Future toCancel)
cancel
if (toCancel != null) {
    return toCancel.cancel(false); 
return false;
voidcancel(List> futures)
cancel
futures.forEach(f -> f.cancel(true));
voidcancelNullableFutures(boolean mayInterruptIfRunning, Iterable> futures)
Cancels all Futures in futures with the mayInterruptIfRunning argument.
for (Future<?> f : futures) {
    if (f != null) {
        f.cancel(mayInterruptIfRunning);
voidcancelScheduledFuture(ScheduledFuture scheduledFuture)
cancel Scheduled Future
ScheduledFuture<?> future = scheduledFuture;
if (future != null && !future.isCancelled()) {
    future.cancel(true);
voidcheckTimeThresholds(long expectedMin, long expectedMax, long expectedOverhead, long start, Map> responses)
check Time Thresholds
long time = getMaxIn(responses) - start;
assert time >= expectedMax && time < expectedMax + expectedOverhead : String
        .format("expectedMax  %d, max %d", expectedMax, time);
time = getMinIn(responses) - start;
assert time >= expectedMin && time < expectedMin + expectedOverhead : String
        .format("expectedMin  %d, min %d", expectedMin, time);
time = getMaxIn(responses) - start;
assert time >= expectedMax && time < expectedMax + expectedOverhead : String
...
Futurecommit(Object tx)
commit
return null;
CompletableFutureconvertFuture(Future future)
convert Future
CompletableFuture<V> brighterFuture = supplyAsync(() -> {
    try {
        return future.get();
    } catch (Exception e1) {
        throw new RuntimeException(e1);
});
return brighterFuture;
...
CompletableFuturecreateFuture()
create Future
return new CompletableFuture<T>();