1package com.runehive.game.service;
3import java.util.Collection;
5import java.util.concurrent.*;
16 private ExecutorService
service = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
19 private BlockingQueue<Future<?>>
pendingTasks =
new LinkedBlockingQueue<>();
34 }
catch (InterruptedException e) {
42 service.awaitTermination(timeout, timeUnit);
43 }
catch (InterruptedException e) {
58 public boolean awaitTermination(
long timeout, TimeUnit unit)
throws InterruptedException {
59 return service.awaitTermination(timeout, unit);
63 public <T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>> tasks)
throws InterruptedException {
64 List<Future<T>> futures =
service.invokeAll(tasks);
65 for (Future<?> future : futures) {
72 public <T> List<Future<T>>
invokeAll(Collection<? extends Callable<T>> tasks,
long timeout, TimeUnit unit)
73 throws InterruptedException {
74 List<Future<T>> futures =
service.invokeAll(tasks, timeout, unit);
75 for (Future<?> future : futures) {
82 public <T> T
invokeAny(Collection<? extends Callable<T>> tasks)
throws InterruptedException, ExecutionException {
83 return service.invokeAny(tasks);
87 public <T> T
invokeAny(Collection<? extends Callable<T>> tasks,
long timeout, TimeUnit unit)
88 throws InterruptedException, ExecutionException, TimeoutException {
89 return service.invokeAny(tasks, timeout, unit);
An ExecutorService that waits for all its events to finish executing.
BlockingQueue< Future<?> > pendingTasks
A list of pending tasks.
public< T > Future< T > submit(Runnable task, T result)
void waitForPendingTasks()
Waits for pending tasks to complete.
ExecutorService service
The service backing this service.
boolean awaitTermination(long timeout, TimeUnit unit)
Future<?> submit(Runnable task)
List< Runnable > shutdownNow()
void execute(Runnable command)
public< T > Future< T > submit(Callable< T > task)
int getPendingTaskAmount()
Gets the number of pending tasks.
public< T > List< Future< T > > invokeAll(Collection<? extends Callable< T > > tasks, long timeout, TimeUnit unit)
public< T > T invokeAny(Collection<? extends Callable< T > > tasks, long timeout, TimeUnit unit)
public< T > List< Future< T > > invokeAll(Collection<? extends Callable< T > > tasks)
public< T > T invokeAny(Collection<? extends Callable< T > > tasks)
void awaitUntilFinished(long timeout, TimeUnit timeUnit)