Example usage for java.util.concurrent ThreadPoolExecutor getLargestPoolSize

List of usage examples for java.util.concurrent ThreadPoolExecutor getLargestPoolSize

Introduction

In this page you can find the example usage for java.util.concurrent ThreadPoolExecutor getLargestPoolSize.

Prototype

public int getLargestPoolSize() 

Source Link

Document

Returns the largest number of threads that have ever simultaneously been in the pool.

Usage

From source file:Main.java

/**
 * //from   ww  w .  ja  va2s  .  co m
 */
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:org.jmangos.commons.threadpool.CommonThreadPoolManager.java

/**
 * @see org.jmangos.commons.threadpool.ThreadPoolManager#fillPoolStats(org.jmangos.commons.threadpool.model.ThreadPoolType)
 *///from  w  w w .  jav a 2s  . c  o  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//  ww w .  j  a  v  a 2 s  .  c  o 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.client.TestMultiParallel.java

/**
 * This is for testing the active number of threads that were used while
 * doing a batch operation. It inserts one row per region via the batch
 * operation, and then checks the number of active threads.
 * For HBASE-3553/*from   w w  w  .j  a  va 2 s  . c om*/
 * @throws IOException
 * @throws InterruptedException
 * @throws NoSuchFieldException
 * @throws SecurityException
 */
@Test(timeout = 300000)
public void testActiveThreadsCount() throws Exception {
    HTable table = new HTable(UTIL.getConfiguration(), TEST_TABLE);
    List<Row> puts = constructPutRequests(); // creates a Put for every region
    table.batch(puts);
    Field poolField = table.getClass().getDeclaredField("pool");
    poolField.setAccessible(true);
    ThreadPoolExecutor tExecutor = (ThreadPoolExecutor) poolField.get(table);
    assertEquals(slaves, tExecutor.getLargestPoolSize());
    table.close();
}