java.util.concurrent.ThreadPoolExecutor#isShutdown ( )源码实例Demo

下面列出了java.util.concurrent.ThreadPoolExecutor#isShutdown ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sofa-jraft   文件: DiscardOldPolicyWithReport.java
@Override
public void rejectedExecution(final Runnable r, final ThreadPoolExecutor e) {
    LOG.error("Thread pool [{}] is exhausted! {}.", threadPoolName, e.toString());

    dumpJvmInfoIfNeeded();

    if (!e.isShutdown()) {
        final BlockingQueue<Runnable> queue = e.getQueue();
        int discardSize = queue.size() >> 1;
        discardSize = discardSize <= 0 ? 1 : discardSize;
        for (int i = 0; i < discardSize; i++) {
            queue.poll();
        }
        e.execute(r);
    }
}
 
源代码2 项目: Thunder   文件: DiscardedPolicyWithReport.java
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (!executor.isShutdown()) {
        BlockingQueue<Runnable> queue = executor.getQueue();
        // 舍弃1/2队列元素,例如7个单位的元素,舍弃3个
        int discardSize = queue.size() >> 1;
        for (int i = 0; i < discardSize; i++) {
            // 从头部移除并返问队列头部的元素
            queue.poll();
        }

        // 添加元素,如果队列满,不阻塞,返回false
        queue.offer(runnable);
    }
}
 
源代码3 项目: Lottor   文件: RejectedPolicy.java
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("txTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (runnable instanceof RejectedRunnable) {
        ((RejectedRunnable) runnable).rejected();
    } else {
        if (!executor.isShutdown()) {
            BlockingQueue<Runnable> queue = executor.getQueue();
            int discardSize = queue.size() >> 1;
            for (int i = 0; i < discardSize; i++) {
                queue.poll();
            }

            try {
                queue.put(runnable);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
 
源代码4 项目: gemfirexd-oss   文件: PooledExecutorWithDMStats.java
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
  if (executor.isShutdown()) {
    throw new RejectedExecutionException(LocalizedStrings.PooledExecutorWithDMStats_EXECUTOR_HAS_BEEN_SHUTDOWN.toLocalizedString());
  } else {
    try {
      PooledExecutorWithDMStats pool = (PooledExecutorWithDMStats)executor;
      pool.bufferQueue.put(r);
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
      RejectedExecutionException e = new RejectedExecutionException(LocalizedStrings.PooledExecutorWithDMStats_INTERRUPTED.toLocalizedString());
      e.initCause(ie);
      throw e;
    }
  }
}
 
@Override
public void rejectedExecution(final Runnable r, final ThreadPoolExecutor e) {
    LOG.error("Thread pool [{}] is exhausted! {}.", threadPoolName, e.toString());

    dumpJvmInfoIfNeeded();

    if (!e.isShutdown()) {
        try {
            e.getQueue().put(r);
        } catch (InterruptedException ignored) {
            // Should not be interrupted
        }
    }
}
 
源代码6 项目: Thunder   文件: RejectedPolicyWithReport.java
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (runnable instanceof RejectedRunnable) {
        ((RejectedRunnable) runnable).rejected(); // 交给用户来处理
    } else {
        if (!executor.isShutdown()) {
            BlockingQueue<Runnable> queue = executor.getQueue();
            // 舍弃1/2队列元素,例如7个单位的元素,舍弃3个
            int discardSize = queue.size() >> 1;
            for (int i = 0; i < discardSize; i++) {
                // 从头部移除并返问队列头部的元素
                queue.poll();
            }

            try {
                // 添加一个元素, 如果队列满,则阻塞
                queue.put(runnable);
            } catch (InterruptedException e) {
                // should not be interrupted
            }
        }
    }
}
 
源代码7 项目: L2jOrg   文件: RejectedExecutionHandlerImpl.java
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
	if (executor.isShutdown()) {
		return;
	}
	
	LOGGER.warn("{} from {} ", r, executor);
}
 
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
  if (executor.isShutdown()) {
    throw new RejectedExecutionException(LocalizedStrings.PooledExecutorWithDMStats_EXECUTOR_HAS_BEEN_SHUTDOWN.toLocalizedString());
  } else {
    try {
      FunctionExecutionPooledExecutor pool = (FunctionExecutionPooledExecutor)executor;
      pool.bufferQueue.put(r);
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
      RejectedExecutionException e = new RejectedExecutionException(LocalizedStrings.PooledExecutorWithDMStats_INTERRUPTED.toLocalizedString());
      e.initCause(ie);
      throw e;
    }
  }
}
 
源代码9 项目: BootNettyRpc   文件: BlockingPolicyWithReport.java
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (!executor.isShutdown()) {
        try {
            // 添加一个元素, 如果队列满,则阻塞
            executor.getQueue().put(runnable);
        } catch (InterruptedException e) {
            // should not be interrupted
        }
    }
}
 
源代码10 项目: tomee   文件: OfferRejectedExecutionHandler.java
@Override
public void rejectedExecution(final Runnable r, final ThreadPoolExecutor tpe) {

    if (null == r || null == tpe || tpe.isShutdown() || tpe.isTerminated() || tpe.isTerminating()) {
        return;
    }

    try {
        if (!tpe.getQueue().offer(r, timeout, seconds)) {
            throw new RejectedExecutionException("Timeout waiting for executor slot: waited " + timeout + " " + seconds.toString().toLowerCase());
        }
    } catch (final InterruptedException e) {
        throw new RejectedExecutionException("Interrupted waiting for executor slot");
    }
}
 
源代码11 项目: yangtools   文件: CachedThreadPoolExecutor.java
@Override
public void rejectedExecution(final Runnable task, final ThreadPoolExecutor executor) {
    if (executor.isShutdown()) {
        throw new RejectedExecutionException("Executor has been shutdown.");
    }

    if (!backingQueue.offer(task)) {
        delegateRejectedExecutionHandler.rejectedExecution(task, executor);
    }
}
 
源代码12 项目: Lottor   文件: DiscardedPolicy.java
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
    if (threadName != null) {
        LOG.error("txTransaction Thread pool [{}] is exhausted, executor={}", threadName, executor.toString());
    }

    if (!executor.isShutdown()) {
        BlockingQueue<Runnable> queue = executor.getQueue();
        int discardSize = queue.size() >> 1;
        for (int i = 0; i < discardSize; i++) {
            queue.poll();
        }
        queue.offer(runnable);
    }
}
 
源代码13 项目: sofa-lookout   文件: BlockExecutionHandler.java
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
    if (!executor.isShutdown()) {
        try {
            executor.getQueue().put(r);
        } catch (InterruptedException e) {
            LOGGER.error("线程打断", e);
        }
    } else {
        LOGGER.error("线程池已经关闭, 丢失任务", r);
    }
}
 
源代码14 项目: Jupiter   文件: DiscardTaskPolicyWithReport.java
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
    logger.error("Thread pool [{}] is exhausted! {}.", threadPoolName, e.toString());

    dumpJvmInfoIfNeeded();

    if (!e.isShutdown()) {
        BlockingQueue<Runnable> queue = e.getQueue();
        int discardSize = queue.size() >> 1;
        for (int i = 0; i < discardSize; i++) {
            queue.poll();
        }
        queue.offer(r);
    }
}
 
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
  if (executor.isShutdown()) {
    throw new RejectedExecutionException("Threadpoolexecutor already shutdown");
  } else {
    try {
      executor.getQueue().put(r);
    } catch (InterruptedException e) {
      throw new RejectedExecutionException(
          "Thread was interrupted while waiting for space to be available in the threadpool", e);
    }
  }
}
 
源代码16 项目: phoenix   文件: ThreadPoolManager.java
static synchronized ThreadPoolExecutor getExecutor(ThreadPoolBuilder builder,
    Map<String, Object> poolCache) {
  ThreadPoolExecutor pool = (ThreadPoolExecutor) poolCache.get(builder.getName());
  if (pool == null || pool.isTerminating() || pool.isShutdown()) {
    pool = getDefaultExecutor(builder);
    LOG.info("Creating new pool for " + builder.getName());
    poolCache.put(builder.getName(), pool);
  }
  ((ShutdownOnUnusedThreadPoolExecutor) pool).addReference();

  return pool;
}
 
源代码17 项目: gemfirexd-oss   文件: PooledExecutorWithDMStats.java
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
  if (executor.isShutdown()) {
    throw new RejectedExecutionException(LocalizedStrings.PooledExecutorWithDMStats_EXECUTOR_HAS_BEEN_SHUTDOWN.toLocalizedString());
  } else {
    try {
      PooledExecutorWithDMStats pool = (PooledExecutorWithDMStats)executor;
      pool.bufferQueue.put(r);
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
      RejectedExecutionException e = new RejectedExecutionException(LocalizedStrings.PooledExecutorWithDMStats_INTERRUPTED.toLocalizedString());
      e.initCause(ie);
      throw e;
    }
  }
}
 
源代码18 项目: pdfcompare   文件: BlockingHandler.java
@Override
public void rejectedExecution(final Runnable r, final ThreadPoolExecutor executor) {
    try {
        if (!executor.isShutdown()) {
            executor.getQueue().put(r);
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
 
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
  if (executor.isShutdown()) {
    throw new RejectedExecutionException("executor has been shutdown");
  } else {
    try {
      executor.getQueue().put(r);
    } catch (InterruptedException ie) {
      Thread.currentThread().interrupt();
      RejectedExecutionException e = new RejectedExecutionException("interrupted");
      e.initCause(ie);
      throw e;
    }
  }
}
 
源代码20 项目: vlingo-actors   文件: ExecutorDispatcher.java
@Override
public void rejectedExecution(final Runnable runnable, final ThreadPoolExecutor executor) {
  if (!executor.isShutdown() && !executor.isTerminated())
    throw new IllegalStateException("Message cannot be sent due to current system resource limitations.");
}