Java 8 ThreadPoolExecutor - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ThreadPoolExecutor class.

This code example shows how to use the following methods: execute, getActiveCount, getQueue, getTaskCount
  synchronized void execute(Runnable task) {
    if (executor == null) {
      throw new RuntimeException("AsyncDataService is already shutdown");
    } 
    if (LOG.isDebugEnabled()) {
      LOG.debug("Current active thread number: " + executor.getActiveCount()
          + " queue size:" + executor.getQueue().size()
          + " scheduled task number:" + executor.getTaskCount());
    } 
    executor.execute(task);
  } 
 
  /** 
   * Gracefully shut down the ThreadPool. Will wait for all data tasks to 
   * finish. 
   */ 
  synchronized void shutdown() { 
    if (executor == null) {
      LOG.warn("AsyncDataService has already shut down.");
    } else { 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getQueue, isShutdown
 
    @Override 
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        if (r instanceof AbstractRunnable) {
            if (((AbstractRunnable) r).isForceExecution()) {
                BlockingQueue<Runnable> queue = executor.getQueue();
                if (!(queue instanceof SizeBlockingQueue)) {
                    throw new ElasticSearchIllegalStateException("forced execution, but expected a size queue"); 
                } 
                try { 
                    ((SizeBlockingQueue) queue).forcePut(r);
                } catch (InterruptedException e) {
                    throw new ElasticSearchInterruptedException(e.getMessage(), e);
                } 
                return; 
            } 
        } 
        rejected.inc();
        StringBuilder sb = new StringBuilder("rejected execution ");
        if (executor.isShutdown()) {

8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: allowCoreThreadTimeOut
        SERVER_MANAGEMENT_LOGGER.debugf("Starting operation handler service %s", context.getController().getName());
        if(executor.getOptionalValue() == null) {
            // Create the default executor 
            final BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(WORK_QUEUE_SIZE);
            final ThreadFactory threadFactory = new JBossThreadFactory(new ThreadGroup(getThreadGroupName()), Boolean.FALSE, null, "%G - %t", null, null, doPrivileged(GetAccessControlContextAction.getInstance()));
            final ThreadPoolExecutor executorService = new ThreadPoolExecutor(POOL_CORE_SIZE, POOL_MAX_SIZE,
                                                            60L, TimeUnit.SECONDS, workQueue,
                                                            threadFactory);
            // Allow the core threads to time out as well 
            executorService.allowCoreThreadTimeOut(true);
            getExecutorInjector().inject(executorService);
        } 
    } 
 
    /** {@inheritDoc} */ 
    @Override 
    public synchronized void stop(StopContext context) {
        // 
    } 
 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: awaitTermination, shutdown, shutdownNow
        } 
    } 
 
    @Override 
    public void stop() throws Exception { 
        executor.shutdown();
        if (!executor.awaitTermination(60, TimeUnit.SECONDS)) {
            executor.shutdownNow();
        } 
    } 
 
    @Override 
    public void addLifeCycleListener(Listener listener) {
        System.err.println("we should implement this!");
    } 
 
    @Override 
    public void removeLifeCycleListener(Listener listener) {
        System.err.println("we should implement this!");
    } 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getActiveCount, getPoolSize
        } 
    } 
 
    @Override 
    public int getIdleThreads() { 
        return executor.getPoolSize() - executor.getActiveCount();
    } 
 
    @Override 
    public int getThreads() { 
        return executor.getPoolSize();
    } 
 
    @Override 
    public boolean isLowOnThreads() { 
        return executor.getActiveCount() >= executor.getMaximumPoolSize();
    } 
 
    @Override 
    public void join() throws InterruptedException {
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 ThreadPoolExecutor Questions & Answers:

See Code Examples for Java 8 ThreadPoolExecutor Methods: