简体   繁体   English

没有stacktrace的线程异常

[英]Thread exception without stacktrace

I set up global exception handler: 我设置了全局异常处理程序:

Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler());

with quite simple implementation: 具有非常简单的实现:

public class DefaultUncaughtExceptionHandler implements UncaughtExceptionHandler {

    public static final Logger logger = LoggerFactory.getLogger(DefaultUncaughtExceptionHandler.class);

    @Override
    public void uncaughtException(Thread t, Throwable e) {
        logger.error("Uncaught Exception detected in thread {}", t, e);
    }

} }

sometimes I see in logs this exception several times: 有时我在日志中多次看到此异常:

[AWT-EventQueue-0] DefaultUncaughtExceptionHandler - Uncaught Exception detected in thread Thread[AWT-EventQueue-0,6,main]
java.lang.ArrayIndexOutOfBoundsException: null

but I cannot find where it comes from. 但我找不到它的来源。

How do you think, why stacktrace is empty? 您如何看待,为什么stacktrace为空? It shouldn't be empty, all threads must be created at least from parent "main" thread or any other. 它不应为空,必须至少从父“主”线程或任何其他线程创建所有线程。

The JIT compiler can make some optimizations and "lose" stack traces. JIT编译器可以进行一些优化和“减少”堆栈跟踪。

You can use following JVM flag to disable this optimization: 您可以使用以下JVM标志来禁用此优化:

-XX:-OmitStackTraceInFastThrow

Reference: http://jawspeak.com/2010/05/26/hotspot-caused-exceptions-to-lose-their-stack-traces-in-production-and-the-fix/ 参考: http//jawspeak.com/2010/05/26/hotspot-caused-exceptions-to-lose-their-stack-traces-in-production-and-the-fix/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM