简体   繁体   English

Java线程异常终止,并带有消息null的异常。

[英]Java thread terminates abnormally with an exception with message null.

I am trying to execute a multithreaded program, using the Executors of Java. 我正在尝试使用Java的执行程序执行多线程程序。 On execution the java thread terminates abnormally. 执行时,java线程异常终止。 I caught the exception , through try-catch, however, the exception has no message in it (null). 我通过try-catch捕获了异常,但是,该异常中没有消息(空)。

The failure is random, however I "suspect" that the failure is happening after I have made function calls in that thread. 该故障是随机的,但是我“怀疑”该故障是在该线程中进行函数调用之后发生的。 I tried to increase the thread stack size to 1024/2048 , but the result remains same. 我试图将线程堆栈的大小增加到1024/2048,但结果仍然相同。

Can someone please point out to the debugging approach to be adopted here. 有人可以指出这里要采用的调试方法吗? Since, I do not have the info about the exception I am not able to proceed with it. 因为,我没有有关异常的信息,所以我无法继续进行处理。

I am working in Windows 64-bit environment, with java 1.6 我在使用Java 1.6的Windows 64位环境中工作

While using the Executors class to create the thread pool use the method that accepts ThreadFactory; 在使用Executors类创建线程池时,请使用接受ThreadFactory的方法。 example ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory) . 示例ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory) In your implementation of the ThreadFactory, assign an UncaughtExceptionHandler; 在ThreadFactory的实现中,分配一个UncaughtExceptionHandler。 example below 下面的例子

public final Thread newThread(final Runnable r) {
    Thread newThread = threadFactory.newThread(r); // you can use default thread factory
    newThread.setName("threadName");
    newThread.setDaemon(Boolean.TRUE);
    newThread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        @Override
        public void uncaughtException(final Thread t, final Throwable e) {
            // log
        }
    });
    return newThread;
}

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

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