Logging thread exceptions in tomcat environment

I wrote a java code snippet for springboot controller:

@GetMapping("/exception")
    public void exceptionInThread() {
        Thread newThread = new Thread(new Runnable() {
                @Override
                public void run() {
                    throw new NullPointerException();
                }
        });
        log.info("daemon: {}, threadGroup: {}, defaultUncaught: {}",
                 newThread.isDaemon(),
                 newThread.getThreadGroup(),
                 Thread.getDefaultUncaughtExceptionHandler()
                 );
        newThread.start();
    }

      

After compiling the project, I run java -jar application.jar

and call restapi ( http: // localhost: 8080 / exception ). I can get NPE traceback.

But in our production environment, we build a sprintboot into a WAR and put the WAR in the Tomapp Webapps directory. Then a strange thing happens. When I ran restapi to run the method, there is no trace of NPE. It's as if there is a default uncaught exception handler that uses an untracked exception. But the application log I printed is the same in both environments (sprintboot app and tomcat webapp):

2017-07-19 10:35:33.479  INFO 38070 --- [nio-8080-exec-1] com.ruan.restful.ThreadController  : daemon: true, threadGroup: java.lang.ThreadGroup[name=main,maxpri=10], defaultUncaught: null

      

This confuses me. Is there something Tomcat for me? Can you guys give me some pointers?

+3


source to share





All Articles