All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.common.thread.ThreadPool Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.snapscript.common.thread;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class ThreadPool implements ScheduledExecutorService {

   private final ScheduledExecutorService executor;
   private final ThreadFactory factory;
   
   public ThreadPool() {
      this(1);
   }
   
   public ThreadPool(int threads) {
      this(threads, 0);
   }
   
   public ThreadPool(int threads, int stack) {
      this.factory = new ThreadBuilder(true, stack);
      this.executor = new ScheduledThreadPoolExecutor(threads, factory);
   }

   @Override
   public void execute(Runnable command) {
      executor.execute(command);
   }

   @Override
   public void shutdown() {
      executor.shutdown();
   }

   @Override
   public List shutdownNow() {
      return executor.shutdownNow();
   }

   @Override
   public boolean isShutdown() {
      return executor.isShutdown();
   }

   @Override
   public boolean isTerminated() {
      return executor.isTerminated();
   }

   @Override
   public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException {
      return executor.awaitTermination(timeout, unit);
   }

   @Override
   public  Future submit(Callable task) {
      return executor.submit(task);
   }

   @Override
   public  Future submit(Runnable task, T result) {
      return executor.submit(task, result);
   }

   @Override
   public Future submit(Runnable task) {
      return executor.submit(task);
   }

   @Override
   public  List> invokeAll(Collection> tasks) throws InterruptedException {
      return executor.invokeAll(tasks);
   }

   @Override
   public  List> invokeAll(Collection> tasks, long timeout, TimeUnit unit) throws InterruptedException {
      return executor.invokeAll(tasks, timeout, unit);
   }

   @Override
   public  T invokeAny(Collection> tasks) throws InterruptedException, ExecutionException {
      return executor.invokeAny(tasks);
   }

   @Override
   public  T invokeAny(Collection> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
      return executor.invokeAny(tasks, timeout, unit);
   }

   @Override
   public ScheduledFuture schedule(Runnable command, long delay, TimeUnit unit) {
      return executor.schedule(command, delay, unit);
   }

   @Override
   public  ScheduledFuture schedule(Callable callable, long delay, TimeUnit unit) {
      return executor.schedule(callable, delay, unit);
   }

   @Override
   public ScheduledFuture scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
      return executor.scheduleAtFixedRate(command, initialDelay, period, unit);
   }

   @Override
   public ScheduledFuture scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
      return executor.scheduleWithFixedDelay(command, initialDelay, delay, unit);
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy