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.apache.solr.client.solrj.TestBackupLBHttpSolrClient.java
@Override public void setUp() throws Exception { super.setUp(); httpClient = HttpClientUtil.createClient(null); HttpClientUtil.setConnectionTimeout(httpClient, 1000); solr = new HashMap<String, SolrInstance>(); commExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 5, TimeUnit.SECONDS, // terminate idle threads after 5 sec new SynchronousQueue<Runnable>(), // directly hand off tasks new DefaultSolrThreadFactory("TestBackupLBHttpSolrServer")); }
From source file:org.rhq.core.pc.operation.OperationManager.java
public void initialize() { timer = new Timer(SENDER_THREAD_POOL_NAME + ".timeout-timer"); // read the javadoc on ThreadPoolExecutor and how max pool size is affected when using LinkedBlockingQueue LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(10000); LoggingThreadFactory threadFactory = new LoggingThreadFactory(SENDER_THREAD_POOL_NAME, true); int maxPoolSize = configuration.getOperationInvokerThreadPoolSize(); ThreadPoolExecutor threadPool = new ThreadPoolExecutor(1, maxPoolSize, 1000, TimeUnit.MILLISECONDS, queue, threadFactory);/*from www . ja v a 2s .co m*/ operationGateway = new OperationThreadPoolGateway(threadPool); }
From source file:metlos.executors.batch.BatchCpuThrottlingExecutorTest.java
@Test public void maxUsage_MultiThreaded() throws Exception { NamingThreadFactory factory = new NamingThreadFactory(); ThreadPoolExecutor e = new ThreadPoolExecutor(10, 10, 0, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(), factory);// w w w . j av a 2 s. co m e.prestartAllCoreThreads(); List<Future<?>> payloadResults = new ArrayList<Future<?>>(); long startTime = System.nanoTime(); //create load for (int i = 0; i < NOF_JOBS; ++i) { Future<?> f = e.submit(new Payload()); payloadResults.add(f); } //wait for it all to finish for (Future<?> f : payloadResults) { f.get(); } long endTime = System.nanoTime(); long time = endTime - startTime; LOG.info("MAX Multithreaded test took " + (time / 1000.0 / 1000.0) + "ms"); ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); long cpuTime = 0; for (Thread t : factory.createdThreads) { long threadCpuTime = threadBean.getThreadCpuTime(t.getId()); LOG.info(t.getName() + ": " + threadCpuTime + "ns"); cpuTime += threadCpuTime; } float actualUsage = (float) cpuTime / time; LOG.info("MAX Multithreaded overall usage: " + actualUsage); }
From source file:org.apache.hadoop.hbase.regionserver.CompactSplitThread.java
/** @param server */ CompactSplitThread(HRegionServer server) { super();/* w w w. j ava 2 s. com*/ this.server = server; this.conf = server.getConfiguration(); this.regionSplitLimit = conf.getInt("hbase.regionserver.regionSplitLimit", Integer.MAX_VALUE); int largeThreads = Math.max(1, conf.getInt("hbase.regionserver.thread.compaction.large", 1)); int smallThreads = conf.getInt("hbase.regionserver.thread.compaction.small", 1); int splitThreads = conf.getInt("hbase.regionserver.thread.split", 1); // if we have throttle threads, make sure the user also specified size Preconditions.checkArgument(largeThreads > 0 && smallThreads > 0); final String n = Thread.currentThread().getName(); this.longCompactions = new ThreadPoolExecutor(largeThreads, largeThreads, 60, TimeUnit.SECONDS, new PriorityBlockingQueue<Runnable>(), new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(n + "-longCompactions-" + System.currentTimeMillis()); return t; } }); this.longCompactions.setRejectedExecutionHandler(new Rejection()); this.shortCompactions = new ThreadPoolExecutor(smallThreads, smallThreads, 60, TimeUnit.SECONDS, new PriorityBlockingQueue<Runnable>(), new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(n + "-shortCompactions-" + System.currentTimeMillis()); return t; } }); this.shortCompactions.setRejectedExecutionHandler(new Rejection()); this.splits = (ThreadPoolExecutor) Executors.newFixedThreadPool(splitThreads, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(n + "-splits-" + System.currentTimeMillis()); return t; } }); int mergeThreads = conf.getInt("hbase.regionserver.thread.merge", 1); this.mergePool = (ThreadPoolExecutor) Executors.newFixedThreadPool(mergeThreads, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(n + "-merges-" + System.currentTimeMillis()); return t; } }); }
From source file:org.hyperledger.fabric.sdk.HFClient.java
private HFClient() { executorService = new ThreadPoolExecutor(CLIENT_THREAD_EXECUTOR_COREPOOLSIZE, CLIENT_THREAD_EXECUTOR_MAXIMUMPOOLSIZE, CLIENT_THREAD_EXECUTOR_KEEPALIVETIME, CLIENT_THREAD_EXECUTOR_KEEPALIVETIMEUNIT, new SynchronousQueue<Runnable>(), r -> { Thread t = threadFactory.newThread(r); t.setDaemon(true);//from www. j a va 2 s .com return t; }); }
From source file:org.wso2.carbon.databridge.agent.thrift.Agent.java
public Agent(AgentConfiguration agentConfiguration) { this.agentConfiguration = agentConfiguration; this.transportPool = new ClientPool().getClientPool(new ClientPoolFactory(), agentConfiguration.getMaxTransportPoolSize(), agentConfiguration.getMaxIdleConnections(), true, agentConfiguration.getEvictionTimePeriod(), agentConfiguration.getMinIdleTimeInPool()); this.secureTransportPool = new SecureClientPool().getClientPool( new SecureClientPoolFactory(agentConfiguration.getTrustStore(), agentConfiguration.getTrustStorePassword()), agentConfiguration.getSecureMaxTransportPoolSize(), agentConfiguration.getSecureMaxIdleConnections(), true, agentConfiguration.getSecureEvictionTimePeriod(), agentConfiguration.getSecureMinIdleTimeInPool()); this.agentAuthenticator = AgentAuthenticatorFactory.getAgentAuthenticator(secureTransportPool); this.dataPublisherList = new LinkedList<DataPublisher>(); this.queueSemaphore = new Semaphore(agentConfiguration.getBufferedEventsSize()); //for the unbounded queue implementation the maximum pool size irrelevant and // only the CorePoolSize number of threads will be created this.threadPool = new ThreadPoolExecutor(agentConfiguration.getPoolSize(), agentConfiguration.getMaxPoolSize(), AgentConstants.DEFAULT_KEEP_ALIVE_TIME, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new DataBridgeThreadFactory("Agent")); }
From source file:org.apache.hadoop.hbase.AcidGuaranteesTestTool.java
private ExecutorService createThreadPool() { int maxThreads = 256; int coreThreads = 128; long keepAliveTime = 60; BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>( maxThreads * HConstants.DEFAULT_HBASE_CLIENT_MAX_TOTAL_TASKS); ThreadPoolExecutor tpe = new ThreadPoolExecutor(coreThreads, maxThreads, keepAliveTime, TimeUnit.SECONDS, workQueue, Threads.newDaemonThreadFactory(toString() + "-shared")); tpe.allowCoreThreadTimeOut(true);// ww w .ja v a2s . co m return tpe; }
From source file:fr.gael.dhus.util.http.ParallelizedDownloadManager.java
/** * Creates a new Manager.// www . j av a2 s .c om * * @param core_pool_size the number of threads to keep in the pool, even if they are idle. * * @param max_pool_size the maximum number of threads to allow in the pool. * * @param keep_alive when the number of threads is greater than the core, this is the * maximum time that excess idle threads will wait for new tasks before * terminating. * * @param time_unit the time unit for the keepAliveTime argument. * * @param client_producer a custom http client provider to use custom http clients. * may be null. * * @param temp_dir base path for incomplete files (temporary directory). * may be null. */ public ParallelizedDownloadManager(int core_pool_size, int max_pool_size, long keep_alive, TimeUnit time_unit, HttpAsyncClientProducer client_producer, Path temp_dir) { BlockingQueue<Runnable> work_queue = new LinkedBlockingDeque<>(); this.threadPool = new ThreadPoolExecutor(core_pool_size, max_pool_size, keep_alive, time_unit, work_queue, new DaemonThreadFactory()); if (client_producer != null) { this.http_client = new InterruptibleHttpClient(client_producer); } else { this.http_client = new InterruptibleHttpClient(); } if (temp_dir != null) { if (!Files.isDirectory(temp_dir)) { throw new IllegalArgumentException("Given temp dir is not a dir"); } this.tempDir = temp_dir; } else { this.tempDir = null; } }
From source file:org.apache.streams.facebook.provider.FacebookFriendFeedProvider.java
private static ExecutorService newFixedThreadPoolWithQueueSize(int numThreads, int queueSize) { return new ThreadPoolExecutor(numThreads, numThreads, 5000L, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(queueSize, true), new ThreadPoolExecutor.CallerRunsPolicy()); }
From source file:com.indeed.imhotep.builder.tsv.TsvConverter.java
public TsvConverter() { executor = new ThreadPoolExecutor(PARALLEL_BUILDS, 10, 30, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(10000), new NamedThreadFactory("Builder", true)); }