关于Java线程池异常不打印问题

为什么80%的码农都做不了架构师?>>>   hot3.png

重写 afterExecute

return new ThreadPoolExecutor(corePoolSize, maximumPoolSize,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue()){
            protected void afterExecute(Runnable r, Throwable t) {
                super.afterExecute(r, t);
                if (t == null && r instanceof Future) {
                    try {
                        Object result = ((Future) r).get();
                    } catch (CancellationException ce) {
                        t = ce;
                    } catch (ExecutionException ee) {
                        t = ee.getCause();
                    } catch (InterruptedException ie) {
                        Thread.currentThread().interrupt(); // ignore/reset
                    }
                }
                if (t != null) {
                    t.printStackTrace();
                }
            }
        };

参考地址

转载于:https://my.oschina.net/linch/blog/2991612

你可能感兴趣的:(关于Java线程池异常不打印问题)