- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我们的一项服务中,有人添加了这样(简化)的一段代码:
public class DeleteMe {
public static void main(String[] args) {
DeleteMe d = new DeleteMe();
for (int i = 0; i < 10_000; ++i) {
d.trigger(i);
}
}
private Future<?> trigger(int i) {
ExecutorService es = Executors.newSingleThreadExecutor();
Future<?> f = es.submit(() -> {
try {
// some long running task
Thread.sleep(10_000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
return f;
}
}
Exception in thread "main" java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@3148f668 rejected from java.util.concurrent.ThreadPoolExecutor@6e005dc9[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1379)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
at java.util.concurrent.Executors$DelegatedExecutorService.submit(Executors.java:678)
at com.erabii.so.DeleteMe.trigger(DeleteMe.java:29)
at com.erabii.so.DeleteMe.main(DeleteMe.java:22)
OutOfMemoryError
- 我完全理解。编写代码的人从未调用过
ExecutorService::shutDown
,从而让它活得太久。当然为每个方法调用创建一个单独的执行器服务是不好的,会被改变;但这正是看到错误的原因。
RejectedExecutionException
会被抛出,特别是它被抛出
here .
- If we cannot queue task, then we try to add a new thread. If it fails, we know we are shut down or saturated and so reject the task.
execute
的文档怎么来的?不提这个?
If the task cannot be submitted for execution, either because this executor has been shutdown or because its capacity has been reached, the task is handled by the current RejectedExecutionHandler.
ExecutorService
是 GC-ed - 可达性和范围是不同的东西,GC 可以清除任何不可达的东西;但有一个
Future<?>
这将保持对该服务的强引用,所以我排除了这一点。
最佳答案
你写了
To be frank initially I though that
ExecutorService
is GC-ed - reachability and scope are different things and GC is allowed to clear anything which is not reachable; but there is aFuture<?>
that will keep a strong reference to that service, so I excluded this.
ExecutorService
不保存在局部变量中,但局部变量本身并不能阻止垃圾收集。
Task java.util.concurrent.FutureTask@3148f668 rejected from
java.util.concurrent.ThreadPoolExecutor@6e005dc9[Terminated,
pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
ThreadPoolExecutor@6e005dc9
的状态指定为
Terminated
.
ExecutorService
是错的。实际类型取决于服务实现,但对于普通的,它将是
FutureTask
的实例它没有引用
ExecutorService
.这在适用于您的案例的异常消息中也可见。
ThreadPoolExecutor
,但它是包装
FinalizableDelegatedExecutorService
收集垃圾并调用
shutdown()
的实例在
ThreadPoolExecutor
实例(瘦包装器通常是优化代码中过早垃圾收集的良好候选者,它只是绕过包装)。
FinalizableDelegatedExecutorService
的基类,类(class)
DelegatedExecutorService
有一个
execute
看起来像这样的实现:
public void execute(Runnable command) {
try {
e.execute(command);
} finally { reachabilityFence(this); }
}
关于java - 单个执行程序服务中的 RejectedExecutionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58714980/
我是 Haskell 世界的新手,我编译了一个简单的 exe.program main = do putStrLn "Hello, what's your name?" name
我正在使用 JUnit,现在我想在运行测试之前执行 Java 程序(主方法)。 即在我的项目中,我有一个包含一个具有 main 方法的类的包。我想在运行测试之前运行它(可能在一个单独的进程中),因为被
我的代码是: char* arg_list[] = { "gnuplot", "gnuplot_script.sh", NULL }; printf("Ready %s %s\n", arg_list
exec() 似乎在服务器上启用(function_exists('exec') 返回 true,并且命令未在 'disable_functions' 变量中列出)但我们得到 警告:出于安全原因,ex
我想从 Adobe AIR 应用程序中按下一个按钮并执行一些已安装的程序。例如,我会有一个名为“Start Winamp”的按钮。当按下它时,它应该直接启动 Winamp.exe...我不想执行一
我学习 CS 有一段时间了,似乎我(或我的许多 friend )从来不了解在制作、安装等方面幕后发生的事情。 纠正我,但是 make 是一种编译一组文件的方法吗? 在 Windows 上“将程序安装到
如何执行 MemoryStream 中的程序,这样我就不必先将它保存到硬盘上。该文件可能不会临时保存到硬盘。该程序必须在内存中 100% 正常运行。 static string s
我使用了一个程序(在 Windows 上),我不会透露其名称,它可以从命令行打开而无需通过任何身份验证。我正在尝试创建一些安全措施以防止其他人以这种方式访问它。 我计划用批处理文件替换这个程序的内
我正在开发一个 Web 应用程序,但我陷入了困境: 我想创建一个简单的标签来触发本地程序的执行如gedit、mozilla firefox等 我的项目基于 HTML、Javascript 和 PHP。
我有一个 C++ 程序需要 root 权限才能执行某些功能。如果我在 su 模式下运行编译后的代码,例如 linux-c5b6:/home/suman # 它满足了我的要求,但是在运行时我想检查我的进
我正在创建一个 shell 副本,但在执行自制程序时遇到了问题。我的意思是,当我想执行诸如 java、ls、wc 等之类的东西时,一切都很好......已经存在于路径变量。 现在我希望能够执行“myl
我试图让一些值显示在电子墨水显示器上(通过 SPI)。我已经编写了软件来初始化显示并显示作为命令行参数传递的值。问题是,由于电子墨水技术,显示需要几秒钟才能完全实现,所以此时显示程序也在运行。 另一个
所以我在 Oracle 11g 上创建了以下过程: create or replace PROCEDURE calc_fee (proc_borrowed_date IN Borrowing.borr
我想让 Maven 目标触发 java 类的执行。我正在尝试使用以下行迁移 Makefile: neotest: mvn exec:java -Dexec.mainClass="org.dha
我想用 os.system 运行命令,但出现错误 c:/fe ' is not recognized as an internal or external command, operable prog
我将Spark 1.5.2用于Spark Streaming应用程序。 Web UI的“执行者”选项卡中的存储内存是什么?如何达到530 MB?如何更改该值? 最佳答案 小心:您使用的非常,非常老旧且
我正在阅读 GitLab CI Multirunner documentation它介绍了如何设置 GitLab CI Multirunner 执行器,但我似乎无法在文档或在线搜索中找到有关更改初始设
我是 C 编程新手。我正在尝试使用 fork()、exec() 和 waitpid() 运行由用户指定的路径给出的程序命令。我已经尝试让它正确运行几个小时了,但我不断收到错误,我不知道如何排除故障,一
我是 Java 和 Selenium 的初学者,我在工作时遇到了 JavascriptExecutor。 想知道:虽然 Remote webdriver 和 Firefox driver 实现了 ja
我正在尝试通过 linux c++ 中的邮件命令发送电子邮件,但 execl 导致错误。 如何使用 exec 发送此命令? /bin/echo llol | /usr/bin/mail -s "tes
我是一名优秀的程序员,十分优秀!