调试intellij中的multiThreads:我怎样才能看到所有抛出的异常? [英] debugging multiThreads in intellij: how can i see the all thrown exceptions?
问题描述
我在java中有一个多线程代码。
I have a multithreaded code in java.
我使用intellij进行调试。我知道如何在线程之间切换调试上下文。
I debug with intellij. I know how to switch debug contexts between threads.
然而,控制台只显示主线程抛出的异常。
Nevertheless the console shows only exception thrown for the main thread.
我怎样才能看到从任何线程抛出的异常?
How can i see the exceptions thrown from any thread?
基本上当我与Executor运行集成测试时,会从辅助线程抛出一些异常。
basically when I run integration test with an Executor, some exception is thrown from secondary thread.
但没有任何内容打印到调试控制台。
But nothing is printed to the debug-console.
实际上代码过得很快,而且从未到达尝试抓住我。
Actually the the code flies and never reach to the try catch i have.
这就像我抛出异常的代码之后无法继续下一步
It's like I cannot step-next after the code that throws an exception
try {
while (true) {
logger.debug("New thread. polling on DB, polling on deployment service");
ConfigAction configAction = configActionFactory.get(ConfigActionsEnum.PushToDeployment);
while (configAction != null) {
configAction = configAction.execute() ? configAction.nextActivity() : null;
}
}
} catch (Exception e) {
e.printStackTrace();
logger.error("DeploymentContextListener run failed", e);
}
而当我使用主线程运行时,相同代码我看到异常:
whereas when I run with the main thread, the same code I see the exception:
public void run() {
try {
while (true) {
logger.debug("New thread. polling on DB, polling on deployment service");
ConfigAction configAction = configActionFactory.get(ConfigActionsEnum.PushToDeployment);
while (configAction != null) {
configAction = configAction.execute() ? configAction.nextActivity() : null;
}
}
} catch (Exception e) {
e.printStackTrace();
logger.error("DeploymentContextListener run failed", e);
}
它写在我有的一个try-catch中
it is written in one of the try-catch i have
} catch (Exception ex) {
logger.error("failed to get from DB: getLatestConfigVersionWaitingForDeploy", ex);
}
推荐答案
我的问题是我用过的:
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(() -> { }
来自我所读过的内容:
from what I have read:
invokeAll - 调用future.get()。等待所有线程完成。
invokeAll - call "future.get()". Wait for all threads to finish.
提交 - >将错误附加到Future对象,而不是std-error
Submit -> attach the errors to Future objects, not the the std-error
执行 - >错误被抛出到std-error
Execute -> the errors are thrown to the std-error
这篇关于调试intellij中的multiThreads:我怎样才能看到所有抛出的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!