java - ThreadPoolExecutor 得到正在运行的Thread实例
巴扎黑
巴扎黑 2017-04-17 11:32:44
0
2
760

文档上只有得到 当前运行的线程数量

我要获得正在运行的,我放进去的runable的实例 怎么得到

巴扎黑
巴扎黑

reply all(2)
迷茫

There should be no such support at the API level. One possible way is to override the beforeExecute and afterExecute methods of ThreadPoolExecutor. You can write the log file before/after the task is executed, and your monitoring process/thread can poll the log to get the current Running task.

Or you can use some thread/inter-process communication methods (such as socket?) to get more real-time results.

巴扎黑

It is true that beforeExecute and afterExecute can be overridden, and then a shared ConcurrentHashMap can be opened. BeforeExecute puts Runnable into HashMap, and afterExecute deletes Runnable from HashMap.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!