List of usage examples for java.util.concurrent ThreadPoolExecutor ThreadPoolExecutor
public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler)
From source file:org.dimitrovchi.conf.service.AbstractService.java
public AbstractService(P parameters) { this.parameters = parameters; final int threadCount = parameters.threadCount() == 0 ? Runtime.getRuntime().availableProcessors() : parameters.threadCount();/* w ww . java 2 s . com*/ this.executor = new ThreadPoolExecutor(threadCount, parameters.threadCount(), parameters.keepAlive(), parameters.timeUnit(), parameters.queueType().createBlockingQueue(parameters.queueSize()), new ThreadPoolExecutor.CallerRunsPolicy()); }
From source file:com.dangdang.ddframe.job.util.concurrent.ExecutorServiceObject.java
public ExecutorServiceObject(final String namingPattern, final int threadSize) { workQueue = new LinkedBlockingQueue<>(); threadPoolExecutor = new ThreadPoolExecutor(threadSize, threadSize, 5L, TimeUnit.MINUTES, workQueue, new BasicThreadFactory.Builder().namingPattern(Joiner.on("-").join(namingPattern, "%s")).build()); threadPoolExecutor.allowCoreThreadTimeOut(true); }
From source file:edu.wpi.checksims.util.threading.ParallelAlgorithm.java
/** * @param threads Number of threads to be used for execution *//*from w ww. j a v a 2 s .c o m*/ public static void setThreadCount(int threads) { checkArgument(threads > 0, "Attempted to set number of threads to " + threads + ", but must be positive integer!"); threadCount = threads; executor.shutdown(); // Set up the executor again with the new thread count executor = new ThreadPoolExecutor(threadCount, threadCount, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new ThreadPoolExecutor.AbortPolicy()); }
From source file:org.apache.synapse.transport.nhttp.util.NativeWorkerPool.java
public NativeWorkerPool(int core, int max, int keepAlive, int queueLength, String threadGroupName, String threadGroupId) {/*from w w w. j a v a2 s . com*/ if (log.isDebugEnabled()) { log.debug("Using native util.concurrent package.."); } executor = new ThreadPoolExecutor(core, max, keepAlive, TimeUnit.SECONDS, queueLength == -1 ? new LinkedBlockingQueue() : new LinkedBlockingQueue(queueLength), new BackportThreadFactory(new ThreadGroup(threadGroupName), threadGroupId)); }
From source file:org.apache.axis2.transport.nhttp.util.BackportWorkerPool.java
public BackportWorkerPool(int core, int max, int keepAlive, int queueLength, String threadGroupName, String threadGroupId) {//ww w. j a va 2 s . c o m executor = new ThreadPoolExecutor(core, max, keepAlive, TimeUnit.SECONDS, queueLength == -1 ? new LinkedBlockingQueue() : new LinkedBlockingQueue(queueLength), new BackportThreadFactory(new ThreadGroup(threadGroupName), threadGroupId)); }
From source file:com.kurento.kmf.content.internal.ContentApiExecutorService.java
/** * Post constructor method; instantiate thread pool. * //w w w .j a v a 2 s.c om * @throws Exception * Error in the creation of the thread pool */ @PostConstruct public void afterPropertiesSet() throws Exception { executor = new ThreadPoolExecutor(config.getPoolCoreSize(), config.getPoolMaxSize(), config.getPoolExecutionTimeout(), TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(config.getPoolMaxQueueSize()), new RejectedExecutionHandler() { @Override public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) { ((RejectableRunnable) r).onExecutionRejected(); } }); }
From source file:org.muehleisen.hannes.taxiapp.TaxiRoute.java
@Override public void run() { log.info(this.getClass().getSimpleName() + " starting..."); BlockingQueue<Runnable> taskQueue = new LinkedBlockingDeque<Runnable>(100); ExecutorService ex = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().availableProcessors(), Integer.MAX_VALUE, TimeUnit.DAYS, taskQueue, new ThreadPoolExecutor.DiscardPolicy()); // create rainbow table for driver lookup log.info("Creating driver license rainbow table."); RouteLogEntry.initLrt();/* w ww .ja v a2 s .c o m*/ // bring up routing service log.info("Bringing up OTP Graph Service from '" + graph + "'."); GraphServiceImpl graphService = new GraphServiceImpl(); graphService.setPath(graph); graphService.startup(); ps = new RetryingPathServiceImpl(graphService, new EarliestArrivalSPTService()); // read taxi files log.info("Reading taxi files from '" + taxilog + "'."); Collection<File> files = FileUtils.listFiles(new File(taxilog), new SuffixFileFilter(".csv.zip"), TrueFileFilter.INSTANCE); for (File f : files) { log.info("Reading '" + f + "'."); try { ZipInputStream z = new ZipInputStream(new FileInputStream(f)); z.getNextEntry(); // ZIP files have many entries. In this case, // only one BufferedReader r = new BufferedReader(new InputStreamReader(z)); r.readLine(); // header String line = null; while ((line = r.readLine()) != null) { RouteLogEntry rle = new RouteLogEntry(line); if (!rle.hasGeo()) { continue; } while (taskQueue.remainingCapacity() < 1) { Thread.sleep(100); } ex.submit(new RouteTask(rle)); } r.close(); z.close(); } catch (Exception e) { log.error("Failed to read taxi file from '" + taxilog + "'.", e); } } ex.shutdown(); try { ex.awaitTermination(Integer.MAX_VALUE, TimeUnit.DAYS); } catch (InterruptedException e) { // ... } log.info(deliveries); }
From source file:com.pinterest.terrapin.storage.ReaderFactory.java
public ReaderFactory(PropertiesConfiguration configuration, FileSystem hadoopFs) { this.configuration = configuration; this.hadoopFs = hadoopFs; int numReaderThreads = this.configuration.getInt(Constants.READER_THREAD_POOL_SIZE, 200); ExecutorService threadPool = new ThreadPoolExecutor(numReaderThreads, numReaderThreads, 0, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>(10000), new ThreadFactoryBuilder().setDaemon(false).setNameFormat("reader-pool-%d").build()); this.readerFuturePool = new ExecutorServiceFuturePool(threadPool); }
From source file:org.efaps.esjp.common.background.Service_Base.java
/** * Instantiates a new service_ base.//from w w w .ja v a 2 s. c om */ protected Service_Base() { final int corePoolSize = 2; final int maxdPoolSize = 10; this.executorService = new ThreadPoolExecutor(corePoolSize, maxdPoolSize, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new BasicThreadFactory.Builder().namingPattern("eFaps-BackgroundProcess-%s").build()); }
From source file:com.kurento.kmf.thrift.internal.ThriftInterfaceExecutorService.java
/** * Post constructor method; instantiate thread pool. * //from ww w. j a v a 2 s.c o m * @throws Exception * Error in the creation of the thread pool */ @PostConstruct public void afterPropertiesSet() throws Exception { executor = new ThreadPoolExecutor(config.getPoolCoreSize(), config.getPoolMaxSize(), config.getPoolExecutionTimeout(), TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(config.getPoolMaxQueueSize()), new RejectedExecutionHandler() { @Override public void rejectedExecution(Runnable r, ThreadPoolExecutor exec) { log.warn("Execution is blocked because the thread bounds and queue capacities are reached"); } }); }