try {
// 前置增强
beforeExecute(wt, task);
try {
// 执行任务
task.run();
} catch (Throwable x) {
thrown = x;
throw new Error(x);
} finally {
// 后置增强
afterExecute(task, thrown);
}
}
// 继承线程池,重写这2个方法
protected void beforeExecute(Thread t, Runnable r) { }
protected void afterExecute(Runnable r, Throwable t) { }
Java多线程——》如何在线程池执行任务前后做额外处理
最新推荐文章于 2023-10-28 00:23:54 发布