java线程single_多线程-SingleThreadExecu中出现java.util.concurrent.RejectedExecutionException的可能原因是什么?...

我在单例中创建以下执行程序:

final private ExecutorService executor = Executors.newSingleThreadExecutor(new ThreadFactory() {

final ThreadFactory delegate = Executors.defaultThreadFactory();

public Thread newThread(Runnable paramAnonymousRunnable) {

Thread localThread = this.delegate.newThread(paramAnonymousRunnable);

localThread.setName("MyTask-" + localThread.getName());

localThread.setDaemon(XXX.this.daemonThread);

return localThread;

}

});

在程序执行期间,对单例的此方法有很多调用。 调用可以在不同的线程中完成,也可以同时进行。

private void send(final String paramString) {

try {

this.executor.execute(new Runnable() {

public void run() {

//DO some interesting stuff

}

});

} catch (Exception localException) {

this.handler.handle(localException);

}

}

在某些时候,以下堆栈开始出现:

java.util.concurrent.RejectedExecutionException

at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1774)

at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:768)

at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:656)

at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:589)

at XXXXX.send(XXXX.java:269)

为什么jvm会抛出这样的异常?

singleThreadExecutor由LinkedBlockingQueue()支持。

而且线程池没有关闭。

有关信息,jvm是oracle jdk 1.6。 用弹簧创建单例。从java.util.concurrent.Executors复制:

public static ExecutorService newSingleThreadExecutor(ThreadFactory threadFactory) {

return new FinalizableDelegatedExecutorService

(new ThreadPoolExecutor(1, 1,

0L, TimeUnit.MILLISECONDS,

new LinkedBlockingQueue(),

threadFactory));

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值