public class MyThreadPoolExecutor extends ThreadPoolExecutor {
public MyThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit,
BlockingQueue<Runnable> workQueue) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
}
/*
* (non-Javadoc)
*
* @see
* java.util.concurrent.ThreadPoolExecutor#beforeExecute(java.lang.Thread,
* java.lang.Runnable)
*/
@Override
protected void beforeExecute(Thread t, Runnable r) {
System.out.println("beforeExecute ThreadName:" + ((Thread) r).getName() + " TID:" + t.getId());
}
/*
* (non-Javadoc)
*
* @see
* java.util.concurrent.ThreadPoolExecutor#afterExecute(java.lang.Runnable,
* java.lang.Throwable)
*/
@Override
protected void afterExecute(Runnable r, Throwable t) {
System.out.println("afterExecute TID:" + Thread.currentThread().getId());
System.out.println("afterExecute PoolSize:" + this.getPoolSize());
}
}
扩展ThreadPoolExecutor
最新推荐文章于 2023-01-12 18:58:48 发布