Example usage for java.util.concurrent ThreadPoolExecutor getMaximumPoolSize

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

Introduction

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

Prototype

public int getMaximumPoolSize() 

Source Link

Document

Returns the maximum allowed number of threads.

Usage

From source file:org.geotools.gce.imagemosaic.ImageMosaicReader.java

/**
 * Constructor.//w  w  w  .  ja  v  a2 s  . c  o  m
 * 
 * @param source
 *            The source object.
 * @throws IOException
 * @throws UnsupportedEncodingException
 * 
 */
public ImageMosaicReader(Object source, Hints uHints) throws IOException {
    super(source, uHints);

    //
    // try to extract a multithreaded loader if available
    //
    if (this.hints.containsKey(Hints.EXECUTOR_SERVICE)) {
        final Object executor = uHints.get(Hints.EXECUTOR_SERVICE);
        if (executor != null && executor instanceof ExecutorService) {
            multiThreadedLoader = (ExecutorService) executor;
            if (LOGGER.isLoggable(Level.FINE)) {
                if (multiThreadedLoader instanceof ThreadPoolExecutor) {
                    final ThreadPoolExecutor tpe = (ThreadPoolExecutor) multiThreadedLoader;
                    LOGGER.fine("Using ThreadPoolExecutor with the following settings: " + "core pool size = "
                            + tpe.getCorePoolSize() + "\nmax pool size = " + tpe.getMaximumPoolSize()
                            + "\nkeep alive time " + tpe.getKeepAliveTime(TimeUnit.MILLISECONDS));
                }
            }
        }
    }
    if (this.hints.containsKey(Hints.MAX_ALLOWED_TILES))
        this.maxAllowedTiles = ((Integer) this.hints.get(Hints.MAX_ALLOWED_TILES));

    //
    // Check source
    //
    if (source instanceof ImageMosaicDescriptor) {
        initReaderFromDescriptor((ImageMosaicDescriptor) source, uHints);
    } else {
        try {
            initReaderFromURL(source, uHints);
        } catch (Exception e) {
            throw new DataSourceException(e);
        }
    }
}

From source file:org.jumpmind.symmetric.service.impl.NodeCommunicationService.java

public int getAvailableThreads(CommunicationType communicationType) {
    ThreadPoolExecutor service = getExecutor(communicationType);
    return service.getMaximumPoolSize() - service.getActiveCount();
}

From source file:org.paxle.filter.robots.impl.RobotsTxtManager.java

/**
 * {@inheritDoc}/*from www  .j a v a  2 s.c om*/
 * @see org.osgi.service.monitor.Monitorable#getStatusVariable(String)
 */
public StatusVariable getStatusVariable(String id) throws IllegalArgumentException {
    if (!VAR_NAMES.contains(id)) {
        throw new IllegalArgumentException("Invalid Status Variable name " + id);
    }

    int val = 0;
    int type = StatusVariable.CM_GAUGE;

    if (id.equals(MONITOR_STORE_SIZE)) {
        val = this.loader.size();
    } else if (id.startsWith(MONITOR_JOBS_PREFIX)) {
        ThreadPoolExecutor execService = this.execService;
        if (id.equals(MONITOR_JOBS_ACTIVE)) {
            val = execService.getActiveCount();
        } else if (id.equals(MONITOR_JOBS_IDLE)) {
            long max = execService.getMaximumPoolSize();
            long active = execService.getActiveCount();
            val = (int) (max - active);
        } else if (id.equals(MONITOR_JOBS_MAX)) {
            val = execService.getMaximumPoolSize();
        } else if (id.equals(MONITOR_JOBS_PENDING)) {
            long enqued = execService.getTaskCount();
            long total = execService.getCompletedTaskCount();
            long active = execService.getActiveCount();
            val = (int) (enqued - total - active);
        } else if (id.equals(MONITOR_JOBS_TOTAL)) {
            val = (int) execService.getCompletedTaskCount();
            type = StatusVariable.CM_CC;
        }
    }

    return new StatusVariable(id, type, val);
}

From source file:org.yccheok.jstock.engine.StockHistoryMonitor.java

public void clearStockCodes() {
    writerLock.lock();/*from  w  w  w . ja v a  2s .  c  om*/

    try {
        final ThreadPoolExecutor threadPoolExecutor = ((ThreadPoolExecutor) pool);
        final int nThreads = threadPoolExecutor.getMaximumPoolSize();

        stockCodes.clear();

        histories.clear();

        threadPoolExecutor.shutdownNow();

        // pool is not valid any more. Discard it and re-create.
        pool = Executors.newFixedThreadPool(nThreads);
    } finally {
        writerLock.unlock();
    }
}

From source file:org.yccheok.jstock.engine.StockHistoryMonitor.java

public void stop() {
    ThreadPoolExecutor threadPoolExecutor = null;
    writerLock.lock();/*from  w  w  w.j a v a  2  s  .co m*/
    try {
        threadPoolExecutor = ((ThreadPoolExecutor) pool);
        final int nThreads = threadPoolExecutor.getMaximumPoolSize();

        // Dangerous. Some users, do expect receive callback once they submit tasks into
        // monitor. However, if we are calling shutdownNow, user may not receive any
        // callback from those submitted tasks, which haven't started yet. Calling
        // shutdown() enables submitted tasks have chances to run once.
        //
        // threadPoolExecutor.shutdownNow();
        threadPoolExecutor.shutdown();
        threadPoolExecutor.purge();

        // pool is not valid any more. Discard it and re-create.
        pool = Executors.newFixedThreadPool(nThreads);
    } finally {
        writerLock.unlock();
    }

    // No unlock after awaitTermination, might cause deadlock.

    // How to wait for infinity?
    try {
        threadPoolExecutor.awaitTermination(100, TimeUnit.DAYS);
    } catch (InterruptedException exp) {
        log.error(null, exp);
    }
}