下面列出了java.util.concurrent.ThreadPoolExecutor#isShutdown ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
}
@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);
}
}
@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();
}
}
}
}
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
}
}
}
@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
}
}
}
}
@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;
}
}
}
@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
}
}
}
@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");
}
}
@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);
}
}
@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);
}
}
@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);
}
}
@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);
}
}
}
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;
}
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 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;
}
}
}
@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.");
}