|
|
沉着的水龙头 · OPENSSL中RSA私钥文件(PEM格式) ...· 2 年前 · |
|
|
慷慨的枕头 · 枚举工具类-反射获取枚举类中变量的所有值 - 知乎· 2 年前 · |
|
|
爽快的充电器 · python读取csv数据写入json,删除 ...· 2 年前 · |
|
|
善良的拐杖 · ES 22 - ...· 3 年前 · |
|
|
含蓄的人字拖 · matlab代码完成copy ...· 3 年前 · |
所以我使用executorservice来创建一个线程池。
ExecutorService executor = Executors.newSingleThreadExecutor();
我正在尝试访问线程池队列中的任务数。我发现没有任何方法可以实现这一点。我知道有一些方法可以在threadpoolexecutor中获取队列大小,但是我如何使用executorservice对象来实现这一点呢?
就像我说的,如果我像这样创建了一个ThreadpoolExecutor,我就可以获得队列信息
ThreadPoolExecutor tpExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>());
我知道我可以使用tpExecutor.queue.size()来获取线程池队列中的任务数。但目前我已经使用Executor Service声明了我的线程池。我该怎么做呢?如果人们可以编写代码并进行演示,那将是值得欣赏的。
您可以将此转换为ThreadPoolExecutor。
ThreadPoolExecutor ex=(ThreadPoolExecutor)executor;ex.getQueue().size();
我认为这应该行得通:
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) this.executorService;
int activeCount = threadPoolExecutor.getActiveCount();
long taskCount = threadPoolExecutor.getTaskCount();
long completedTaskCount = threadPoolExecutor.getCompletedTaskCount();
long tasksToDo = taskCount - completedTaskCount - activeCount;
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2023 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号: 粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
扫码关注腾讯云开发者
领取腾讯云代金券
|
|
慷慨的枕头 · 枚举工具类-反射获取枚举类中变量的所有值 - 知乎 2 年前 |