Last active
August 29, 2015 14:27
-
-
Save baoyongzhang/b2b63705b7b301f3031a to your computer and use it in GitHub Desktop.
Java线程池异常会被吞掉,需要手动获取异常信息
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mExecutor = new ScheduledThreadPoolExecutor(6) { | |
@Override | |
protected void afterExecute(Runnable r, Throwable t) { | |
super.afterExecute(r, t); | |
if (t == null && r instanceof Future<?>) { | |
try { | |
Future<?> future = (Future<?>) r; | |
if (future.isDone()) | |
future.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(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment