开发者

Java: synchronized(Object) and RejectedExecutionException

I have this problem:

I have a few threads which access one object with synchronized(Object) { ... }

But sometimes this exception is raised:

ex开发者_StackOverflow中文版ecute: java.util.concurrent.RejectedExecutionException

Why? And what should I do with it?

Thanks


That exception is meant to be raised by Executor.execute - you certainly shouldn't be seeing it just by accessing objects in a synchronized block.

Have a look at the rest of the stack trace to work out exactly where it's occurring, and look at the message to see if that gives you any more information about why you're getting it. As Todd commented, it would usually be due to something like a full work queue.

For example, ThreadPoolExecutor will throw this exception if the queue is uses to buffer tasks to be run refuses to accept more items. This usually indicates that your system is overloaded, or you've misconfigured the executor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜