[英]How to get task completed count for pool
class {
private ExecutorService pool;
public void go() {
pool = Executors.newSingleThreadExecutor();
pool.shutdown();
//logger.log(Level.INFO, "Actual db records added = ["+ + "]");
} //end go
public void update() {
pool.submit(new ItemDispatcher(lse));
} //end update
} //end class
public class ItemDispatcher implements Runnable {
//do work
}
I'm looking to log the total number of execution tasks that completed for my above scenario. 我希望记录上述方案中已完成的执行任务总数。 How can I do this.
我怎样才能做到这一点。 each time on update() method, I submit a task to
ItemDispatcher
. 每次使用update()方法时,我都会向
ItemDispatcher
提交任务。 I want to know how many times tasks completed after I call shutdown on pool. 我想知道在调用池关闭后完成任务多少次。
I don't think the pool itself keeps those sort of figures. 我认为游泳池本身并没有保留这些数字。 You can do it yourself fairly easily though:
不过,您可以自己轻松地完成此操作:
Have an AtomicInteger
, have each task increment the AtomicInteger
when it starts running. 有一个
AtomicInteger
,让每个任务在开始运行时递增AtomicInteger
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.