List of usage examples for java.util.concurrent ThreadPoolExecutor getPoolSize
public int getPoolSize()
From source file:PoolSize.java
public static void main(String[] args) { ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 20, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue()); System.out.println(executor.getPoolSize()); }
From source file:com.l2jfree.util.concurrent.L2ThreadPool.java
private static long getPoolSize(ThreadPoolExecutor[] threadPools) { long result = 0; for (ThreadPoolExecutor threadPool : threadPools) result += threadPool.getPoolSize(); return result; }
From source file:eu.cassandra.sim.utilities.Utils.java
public static void printExecutorSummary(ThreadPoolExecutor executor) { System.out.println(String.format( "[monitor] [%d/%d] Active: %d, Completed: %d, Task: %d, isShutdown: %s, isTerminated: %s", executor.getPoolSize(), executor.getCorePoolSize(), executor.getActiveCount(), executor.getCompletedTaskCount(), executor.getTaskCount(), executor.isShutdown(), executor.isTerminated()));/* ww w. jav a 2s . co m*/ }
From source file:Main.java
/** * /*from w w w. j a v a2 s . c om*/ */ protected static void decorateProperties(ThreadPoolExecutor executor, Properties properties) { if (executor != null) { if (properties != null) { properties.setProperty("thread-keep-alive-time", Long.toString(executor.getKeepAliveTime(TimeUnit.MILLISECONDS))); properties.setProperty("thread-pool-size-largest", Integer.toString(executor.getLargestPoolSize())); properties.setProperty("thread-pool-size-minimum", Integer.toString(executor.getCorePoolSize())); properties.setProperty("thread-pool-size-maximum", Integer.toString(executor.getMaximumPoolSize())); properties.setProperty("thread-pool-size", Integer.toString(executor.getPoolSize())); properties.setProperty("runnable-completed-count", Long.toString(executor.getCompletedTaskCount())); properties.setProperty("runnable-active-count", Integer.toString(executor.getActiveCount())); properties.setProperty("queue-size", Integer.toString(executor.getQueue().size())); properties.setProperty("queue-capacity-remaining", Integer.toString(executor.getQueue().remainingCapacity())); } } }
From source file:net.darkmist.clf.Main.java
private void handleFiles(String fileNames[], int off, int len) { DirTraverser traverser;/*from ww w . j av a 2 s . c o m*/ Queue<File> files; ExecutorService executor; // convert fileNames to Files and put them in a Queue files = Util.newQueue(Util.getStringToFileConverter(), fileNames, off, len); //executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); executor = MoreExecutors.newCurrentThreadPool(); traverser = new DirTraverser(files, new ExecutorFileHandler(executor, this)); // let her rip traverser.run(); // all done traversing... shutdown the executor executor.shutdown(); // and wait for it while (!executor.isTerminated()) { try { executor.awaitTermination(STATUS_TIME, STATUS_UNIT); } catch (InterruptedException e) { logger.warn("Ignoring InterruptedException until thread pool executor stops", e); } if (logger.isDebugEnabled() && executor instanceof ThreadPoolExecutor) { ThreadPoolExecutor pool = (ThreadPoolExecutor) executor; logger.debug("ThreadPool size=" + pool.getPoolSize() + " active=" + pool.getActiveCount() + " queue=" + pool.getQueue().size()); } } executor = null; logger.debug("handleFiles done..."); }
From source file:com.alibaba.wasp.executor.TestExecutorService.java
@Test public void testExecutorService() throws Exception { int maxThreads = 5; int maxTries = 10; int sleepInterval = 10; Server mockedServer = mock(Server.class); when(mockedServer.getConfiguration()).thenReturn(conf); // Start an executor service pool with max 5 threads ExecutorService executorService = new ExecutorService("unit_test"); executorService.startExecutorService(ExecutorType.MASTER_SERVER_OPERATIONS, maxThreads); Executor executor = executorService.getExecutor(ExecutorType.MASTER_SERVER_OPERATIONS); ThreadPoolExecutor pool = executor.threadPoolExecutor; // Assert no threads yet assertEquals(0, pool.getPoolSize()); AtomicBoolean lock = new AtomicBoolean(true); AtomicInteger counter = new AtomicInteger(0); // Submit maxThreads executors. for (int i = 0; i < maxThreads; i++) { executorService.submit(new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter)); }/*w w w. j a v a2 s . com*/ // The TestEventHandler will increment counter when it starts. int tries = 0; while (counter.get() < maxThreads && tries < maxTries) { LOG.info("Waiting for all event handlers to start..."); Thread.sleep(sleepInterval); tries++; } // Assert that pool is at max threads. assertEquals(maxThreads, counter.get()); assertEquals(maxThreads, pool.getPoolSize()); ExecutorStatus status = executor.getStatus(); assertTrue(status.queuedEvents.isEmpty()); assertEquals(5, status.running.size()); checkStatusDump(status); // Now interrupt the running Executor synchronized (lock) { lock.set(false); lock.notifyAll(); } // Executor increments counter again on way out so.... test that happened. while (counter.get() < (maxThreads * 2) && tries < maxTries) { System.out.println("Waiting for all event handlers to finish..."); Thread.sleep(sleepInterval); tries++; } assertEquals(maxThreads * 2, counter.get()); assertEquals(maxThreads, pool.getPoolSize()); // Add more than the number of threads items. // Make sure we don't get RejectedExecutionException. for (int i = 0; i < (2 * maxThreads); i++) { executorService.submit(new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter)); } // Now interrupt the running Executor synchronized (lock) { lock.set(false); lock.notifyAll(); } // Make sure threads are still around even after their timetolive expires. Thread.sleep(ExecutorService.Executor.keepAliveTimeInMillis * 2); assertEquals(maxThreads, pool.getPoolSize()); executorService.shutdown(); assertEquals(0, executorService.getAllExecutorStatuses().size()); // Test that submit doesn't throw NPEs executorService.submit(new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter)); }
From source file:com.dianping.dpsf.jmx.DpsfResponsorMonitor.java
@MBeanMeta(ignore = true) public int getThreadPoolSize(int port) { ThreadPoolExecutor threadPool = getThreadPool(port); return threadPool != null ? threadPool.getPoolSize() : -1; }
From source file:org.jmangos.commons.threadpool.CommonThreadPoolManager.java
/** * @see org.jmangos.commons.threadpool.ThreadPoolManager#fillPoolStats(org.jmangos.commons.threadpool.model.ThreadPoolType) *///from w ww . j a v a 2s. co m @Override public PoolStats fillPoolStats(final ThreadPoolType poolType) { ThreadPoolExecutor executor = null; switch (poolType) { case INSTANT: executor = this.instantPool; break; case SCHEDULED: default: executor = this.scheduledPool; break; } final PoolStats stats = new PoolStats(poolType); stats.setActiveCount(executor.getActiveCount()); stats.setCompletedTaskCount(executor.getCompletedTaskCount()); stats.setCorePoolSize(executor.getCorePoolSize()); stats.setLargestPoolSize(executor.getLargestPoolSize()); stats.setMaximumPoolSize(executor.getMaximumPoolSize()); stats.setPoolSize(executor.getPoolSize()); stats.setQueueSize(executor.getQueue().size()); stats.setTaskCount(executor.getTaskCount()); return stats; }
From source file:org.opennms.newts.gsod.ImportRunner.java
private Observable<Boolean> parMap(Observable<List<Sample>> samples, MetricRegistry metrics, Func1<List<Sample>, Boolean> insert) { final Timer waitTime = metrics.timer("wait-time"); @SuppressWarnings("serial") final BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>( m_maxThreadQueueSize == 0 ? m_threadCount * 3 : m_maxThreadQueueSize) { @Override//from w w w .j a v a 2 s .co m public boolean offer(Runnable r) { try (Context time = waitTime.time()) { this.put(r); return true; } catch (InterruptedException e) { throw Exceptions.propagate(e); } } @Override public boolean add(Runnable r) { try (Context time = waitTime.time()) { this.put(r); return true; } catch (InterruptedException e) { throw Exceptions.propagate(e); } } }; final ThreadPoolExecutor executor = new ThreadPoolExecutor(m_threadCount, m_threadCount, 0L, TimeUnit.MILLISECONDS, workQueue); metrics.register("active-threads", new Gauge<Integer>() { @Override public Integer getValue() { return executor.getActiveCount(); } }); metrics.register("pool-size", new Gauge<Integer>() { @Override public Integer getValue() { return executor.getPoolSize(); } }); metrics.register("largest-pool-size", new Gauge<Integer>() { @Override public Integer getValue() { return executor.getLargestPoolSize(); } }); metrics.register("work-queue-size", new Gauge<Integer>() { @Override public Integer getValue() { return workQueue.size(); } }); return parMap(samples, executor, metrics, insert); }
From source file:org.apache.hadoop.hbase.executor.TestExecutorService.java
@Test public void testExecutorService() throws Exception { int maxThreads = 5; int maxTries = 10; int sleepInterval = 10; Server mockedServer = mock(Server.class); when(mockedServer.getConfiguration()).thenReturn(HBaseConfiguration.create()); // Start an executor service pool with max 5 threads ExecutorService executorService = new ExecutorService("unit_test"); executorService.startExecutorService(ExecutorType.MASTER_SERVER_OPERATIONS, maxThreads); Executor executor = executorService.getExecutor(ExecutorType.MASTER_SERVER_OPERATIONS); ThreadPoolExecutor pool = executor.threadPoolExecutor; // Assert no threads yet assertEquals(0, pool.getPoolSize()); AtomicBoolean lock = new AtomicBoolean(true); AtomicInteger counter = new AtomicInteger(0); // Submit maxThreads executors. for (int i = 0; i < maxThreads; i++) { executorService.submit(new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter)); }/*from w ww . ja v a 2s .c o m*/ // The TestEventHandler will increment counter when it starts. int tries = 0; while (counter.get() < maxThreads && tries < maxTries) { LOG.info("Waiting for all event handlers to start..."); Thread.sleep(sleepInterval); tries++; } // Assert that pool is at max threads. assertEquals(maxThreads, counter.get()); assertEquals(maxThreads, pool.getPoolSize()); ExecutorStatus status = executor.getStatus(); assertTrue(status.queuedEvents.isEmpty()); assertEquals(5, status.running.size()); checkStatusDump(status); // Now interrupt the running Executor synchronized (lock) { lock.set(false); lock.notifyAll(); } // Executor increments counter again on way out so.... test that happened. while (counter.get() < (maxThreads * 2) && tries < maxTries) { System.out.println("Waiting for all event handlers to finish..."); Thread.sleep(sleepInterval); tries++; } assertEquals(maxThreads * 2, counter.get()); assertEquals(maxThreads, pool.getPoolSize()); // Add more than the number of threads items. // Make sure we don't get RejectedExecutionException. for (int i = 0; i < (2 * maxThreads); i++) { executorService.submit(new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter)); } // Now interrupt the running Executor synchronized (lock) { lock.set(false); lock.notifyAll(); } // Make sure threads are still around even after their timetolive expires. Thread.sleep(ExecutorService.Executor.keepAliveTimeInMillis * 2); assertEquals(maxThreads, pool.getPoolSize()); executorService.shutdown(); assertEquals(0, executorService.getAllExecutorStatuses().size()); // Test that submit doesn't throw NPEs executorService.submit(new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter)); }