线程监控
实现线程监控需要继承ThreadPoolExecutor类,并实现以下方法
public class MyThreadPoolLister extends ThreadPoolExecutor {
public ForkJoinTest(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit,
BlockingQueue<Runnable> workQueue) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
}
//线程工作之前都会执行的方法
protected void beforeExecute(Thread t, Runnable r) {
super.beforeExecute(t, r);
}
//线程工作后会执行的方法
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
}
//关闭线程之前会执行的方法
protected void terminated() {
super.terminated();
}
}
其中的方法
ForkJoin监控
ForkJoinn有以下方法可以实现对线程的监控