List of usage examples for java.util.concurrent ThreadPoolExecutor setCorePoolSize
public void setCorePoolSize(int corePoolSize)
From source file:com.alibaba.otter.node.etl.common.pipe.impl.http.archive.ArchiveBean.java
public void adjustPoolSize(int newPoolSize) { if (newPoolSize != poolSize) { poolSize = newPoolSize;/*from w w w . j a v a 2 s. c o m*/ if (executor instanceof ThreadPoolExecutor) { ThreadPoolExecutor pool = (ThreadPoolExecutor) executor; pool.setCorePoolSize(newPoolSize); pool.setMaximumPoolSize(newPoolSize); } } }
From source file:com.alibaba.otter.node.etl.load.loader.db.FileLoadAction.java
private void adjustPoolSize(FileLoadContext context) { Pipeline pipeline = context.getPipeline(); int newPoolSize = pipeline.getParameters().getFileLoadPoolSize(); if (newPoolSize != poolSize) { poolSize = newPoolSize;/*from www. j a v a 2 s . com*/ if (executor instanceof ThreadPoolExecutor) { ThreadPoolExecutor pool = (ThreadPoolExecutor) executor; pool.setCorePoolSize(newPoolSize); pool.setMaximumPoolSize(newPoolSize); } } }
From source file:com.alibaba.otter.node.etl.OtterController.java
public void setThreadPoolSize(int size) { if (executorService instanceof ThreadPoolExecutor) { ThreadPoolExecutor pool = (ThreadPoolExecutor) executorService; pool.setCorePoolSize(size); pool.setMaximumPoolSize(size);//w w w . j a va2 s . com } }
From source file:com.espertech.esper.example.stockticker.TestStockTickerMultithreaded.java
public void performTest(int numberOfThreads, int numberOfTicksToSend, int ratioPriceOutOfLimit, int numberOfSecondsWaitForCompletion) { final int totalNumTicks = numberOfTicksToSend + 2 * TestStockTickerGenerator.NUM_STOCK_NAMES; log.info(".performTest Generating data, numberOfTicksToSend=" + numberOfTicksToSend + " ratioPriceOutOfLimit=" + ratioPriceOutOfLimit); StockTickerEventGenerator generator = new StockTickerEventGenerator(); LinkedList stream = generator.makeEventStream(numberOfTicksToSend, ratioPriceOutOfLimit, TestStockTickerGenerator.NUM_STOCK_NAMES, StockTickerRegressionConstants.PRICE_LIMIT_PCT_LOWER_LIMIT, StockTickerRegressionConstants.PRICE_LIMIT_PCT_UPPER_LIMIT, StockTickerRegressionConstants.PRICE_LOWER_LIMIT, StockTickerRegressionConstants.PRICE_UPPER_LIMIT, true);/*from w w w .ja v a 2s. c o m*/ log.info(".performTest Send limit and initial tick events - singlethreaded"); for (int i = 0; i < TestStockTickerGenerator.NUM_STOCK_NAMES * 2; i++) { Object theEvent = stream.removeFirst(); epService.getEPRuntime().sendEvent(theEvent); } log.info(".performTest Loading thread pool work queue, numberOfRunnables=" + stream.size()); ThreadPoolExecutor pool = new ThreadPoolExecutor(0, numberOfThreads, 99999, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); for (Object theEvent : stream) { SendEventRunnable runnable = new SendEventRunnable(epService, theEvent); pool.execute(runnable); } log.info(".performTest Starting thread pool, threads=" + numberOfThreads); pool.setCorePoolSize(numberOfThreads); log.info(".performTest Listening for completion"); EPRuntimeUtil.awaitCompletion(epService.getEPRuntime(), totalNumTicks, numberOfSecondsWaitForCompletion, 1, 10); pool.shutdown(); // Check results : make sure the given ratio of out-of-limit stock prices was reported int expectedNumEmitted = (numberOfTicksToSend / ratioPriceOutOfLimit) + 1; assertTrue(listener.getSize() == expectedNumEmitted); log.info(".performTest Done test"); }
From source file:com.redhat.example.rules.runtimestats.DefaultRuleSimulator.java
public void setJittingThreads(int jittingThreads) { this.jittingThreads = jittingThreads; int n = jittingThreads > 0 ? jittingThreads : Runtime.getRuntime().availableProcessors(); ThreadPoolExecutor ex = (ThreadPoolExecutor) ExecutorProviderFactory.getExecutorProvider().getExecutor(); if (n != ex.getCorePoolSize()) { ex.setCorePoolSize(n); ex.setMaximumPoolSize(n);//from w w w .j a v a 2 s. c o m } }
From source file:com.espertech.esper.filter.TestIndexTreeBuilderMultithreaded.java
private void performMultithreadedTest(FilterHandleSetNode topNode, int numberOfThreads, int numberOfRunnables, int numberOfSecondsSleep) throws Exception { log.info(".performMultithreadedTest Loading thread pool work queue,numberOfRunnables=" + numberOfRunnables); ThreadPoolExecutor pool = new ThreadPoolExecutor(0, numberOfThreads, 99999, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); for (int i = 0; i < numberOfRunnables; i++) { IndexTreeBuilderRunnable runnable = new IndexTreeBuilderRunnable(eventType, topNode, testFilterSpecs, matchedEvents, unmatchedEvents); pool.execute(runnable);/*from w w w . jav a2s . c om*/ } log.info(".performMultithreadedTest Starting thread pool, threads=" + numberOfThreads); pool.setCorePoolSize(numberOfThreads); // Sleep X seconds sleep(numberOfSecondsSleep); log.info(".performMultithreadedTest Completed, numberOfRunnables=" + numberOfRunnables + " numberOfThreads=" + numberOfThreads + " completed=" + pool.getCompletedTaskCount()); pool.shutdown(); pool.awaitTermination(1, TimeUnit.SECONDS); assertTrue(pool.getCompletedTaskCount() == numberOfRunnables); }
From source file:com.alibaba.otter.node.etl.extract.extractor.DatabaseExtractor.java
private void adjustPoolSize(int newPoolSize) { if (newPoolSize != poolSize) { poolSize = newPoolSize;/*w ww. jav a 2 s. co m*/ if (executor instanceof ThreadPoolExecutor) { ThreadPoolExecutor pool = (ThreadPoolExecutor) executor; pool.setCorePoolSize(newPoolSize); pool.setMaximumPoolSize(newPoolSize); } } }
From source file:com.alibaba.otter.node.etl.load.loader.db.DbLoadAction.java
private void adjustPoolSize(DbLoadContext context) { Pipeline pipeline = context.getPipeline(); int newPoolSize = pipeline.getParameters().getLoadPoolSize(); if (newPoolSize != poolSize) { poolSize = newPoolSize;//w w w. ja v a 2 s . c om if (executor instanceof ThreadPoolExecutor) { ThreadPoolExecutor pool = (ThreadPoolExecutor) executor; pool.setCorePoolSize(newPoolSize); pool.setMaximumPoolSize(newPoolSize); } } }
From source file:org.apache.hadoop.hbase.ipc.TestFifoRpcScheduler.java
private ThreadPoolExecutor disableHandlers(RpcScheduler scheduler) { ThreadPoolExecutor rpcExecutor = null; try {// ww w. j a va 2 s. c o m Field ExecutorField = scheduler.getClass().getDeclaredField("executor"); ExecutorField.setAccessible(true); scheduler.start(); rpcExecutor = (ThreadPoolExecutor) ExecutorField.get(scheduler); rpcExecutor.setMaximumPoolSize(1); rpcExecutor.allowCoreThreadTimeOut(true); rpcExecutor.setCorePoolSize(0); rpcExecutor.setKeepAliveTime(1, TimeUnit.MICROSECONDS); // Wait for 2 seconds, so that idle threads will die Thread.sleep(2000); } catch (NoSuchFieldException e) { LOG.error("No such field exception:" + e); } catch (IllegalAccessException e) { LOG.error("Illegal access exception:" + e); } catch (InterruptedException e) { LOG.error("Interrupted exception:" + e); } return rpcExecutor; }