Example usage for java.util.concurrent ThreadPoolExecutor getActiveCount

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

Introduction

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

Prototype

public int getActiveCount() 

Source Link

Document

Returns the approximate number of threads that are actively executing tasks.

Usage

From source file:Main.java

public static int getActiveCount(Class clazz) {
    ThreadPoolExecutor executor = (ThreadPoolExecutor) getExecutorService(clazz);
    return executor.getActiveCount();
}

From source file:Main.java

/**
 * @param exec//from  w w w  .  j  a v  a 2s.c  o m
 * @param checkInterval
 * @param shutdown
 */
public static void checkBlockPoolCompleted(ThreadPoolExecutor exec, int checkInterval, boolean shutdown) {
    while (true) {
        int activite = exec.getActiveCount();
        waitFor(checkInterval);
        if (activite == 0) {
            break;
        }
    }

    if (shutdown) {
        exec.shutdown();
        try {
            exec.awaitTermination(60, TimeUnit.SECONDS);
        } catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
    }
}

From source file:com.qmetry.qaf.automation.integration.ResultUpdator.java

public static void awaitTermination() {
    if (hasActivePool) {
        ThreadPoolExecutor pool = getPool();
        while (pool.getActiveCount() > 0) {
            logger.info("Result updator : Remaining " + pool.getActiveCount() + " result to be update.");
            try {
                pool.awaitTermination(5, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                e.printStackTrace();/* w  w w . j  ava2s  .c  om*/
            }
        }
        System.out.println("Result updator : Remaining " + pool.getActiveCount() + " result to be update.");
        try {
            pool.shutdownNow();
        } catch (Exception e) {
            e.printStackTrace();
        }
        hasActivePool = false;
    }
}

From source file:com.sm.store.Utils.java

/**
 * Check if the thread pool is overload or not
 * @param pools//  w w  w .  ja  v a2 s  .  co  m
 * @return true or false
 */
public static boolean isOverLoaded(ThreadPoolExecutor pools) {
    int remain = pools.getQueue().remainingCapacity();
    int active = pools.getActiveCount();
    if (remain < active) {
        logger.info("Remaining capacity " + remain + " is less than active threads " + active);
        return true;
    } else
        return false;
}

From source file:com.sm.transport.Utils.java

public static boolean isOverLoaded(ThreadPoolExecutor pools) {
    int remain = pools.getQueue().remainingCapacity();
    int active = pools.getActiveCount();
    if (remain < active) {
        logger.info("Remaining capacity " + remain + " is less than active threads " + active);
        return true;
    } else//w  w  w  . j a  v a  2  s.  c  o  m
        return false;
}

From source file:com.l2jfree.util.concurrent.L2ThreadPool.java

private static int getTaskCount(ThreadPoolExecutor[] threadPools) {
    int result = 0;

    for (ThreadPoolExecutor threadPool : threadPools)
        result += threadPool.getQueue().size() + threadPool.getActiveCount();

    return result;
}

From source file:com.l2jfree.util.concurrent.L2ThreadPool.java

private static boolean awaitTermination(long timeoutInMillisec) throws InterruptedException {
    final long begin = System.currentTimeMillis();

    while (System.currentTimeMillis() - begin < timeoutInMillisec) {
        boolean done = true;

        for (ThreadPoolExecutor threadPool : getThreadPools())
            done &= threadPool.awaitTermination(10, TimeUnit.MILLISECONDS) && threadPool.getActiveCount() == 0;

        if (done)
            return true;
    }//from   w w  w  .j  a va  2  s.  c  om

    return false;
}

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()));/*from   ww  w. j ava  2 s. c o  m*/
}

From source file:Main.java

/**
 * /*from  w w w  .ja v  a2  s .com*/
 */
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:com.stgmastek.birt.report.ReportService.java

public int getCurrentActiveCount() {
    if (!isDestroyed()) {
        if (service instanceof ThreadPoolExecutor) {
            ThreadPoolExecutor executor = (ThreadPoolExecutor) service;
            return executor.getActiveCount();
        }/*w w w  .j a  v  a  2  s . co  m*/
    }
    return -1;
}