Java:同步(对象)和RejectedExecutionException

发布于 2024-08-16 05:22:27 字数 212 浏览 4 评论 0原文

我有这个问题:

我有几个线程使用 synchronized(Object) { ... } 访问一个对象,

但有时会引发此异常:

execute: java.util.concurrent.RejectedExecutionException为什么

?我应该用它做什么?

谢谢

I have this problem:

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

But sometimes this exception is raised:

execute: java.util.concurrent.RejectedExecutionException

Why? And what should I do with it?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野生奥特曼 2024-08-23 05:22:27

该异常是由 Executor.execute 引发的 - 您当然不应该仅仅通过访问同步块中的对象来看到它。

查看堆栈跟踪的其余部分,以准确找出它发生的位置,并查看消息,看看这是否为您提供了有关获取该消息的原因的更多信息。正如托德评论的那样,这通常是由于工作队列已满之类的原因。

例如,如果队列用于缓冲要运行的任务拒绝接受更多项目,则 ThreadPoolExecutor 将抛出此异常。这通常表明您的系统过载,或者您错误配置了执行器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文