com.meliorbis.numerics.threading.MultiThreadedExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Numerics Show documentation
Show all versions of Numerics Show documentation
A library for working with large multi-dimensional arrays and the functions they represent
/**
*
*/
package com.meliorbis.numerics.threading;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
import java.util.logging.Logger;
import com.meliorbis.numerics.NumericsException;
/**
* Executes callables on a configured ExecutorService
*
* @author toby
*/
public class MultiThreadedExecutor implements Executor
{
private static final int DEFAULT_THREAD_COUNT = 0;
private final int _threadCount;
private final ForkJoinPool _pool;
private CurrentThreadExecutor _currentThreadExec;
public MultiThreadedExecutor()
{
this(DEFAULT_THREAD_COUNT);
}
public MultiThreadedExecutor(int threadCount_)
{
_currentThreadExec = new CurrentThreadExecutor();
if(threadCount_ == 0)
{
_pool = ForkJoinPool.commonPool();
}
else
{
_pool = new ForkJoinPool(threadCount_);
}
Logger.getAnonymousLogger().info("Parallelism: "+_pool.getParallelism());
_threadCount = _pool.getParallelism();
}
public MultiThreadedExecutor clone()
{
return new MultiThreadedExecutor(_threadCount);
}
private class BatchAction implements Callable