扩展ThreadPoolExecutor

来源:互联网 发布:家常菜谱软件下载 编辑:程序博客网 时间:2024/06/14 14:00
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());    }}
原创粉丝点击