添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
憨厚的移动电源  ·  GitHub - zanllp/sion: ...·  2 月前    · 
英姿勃勃的白开水  ·  Excel Vba ...·  2 年前    · 
求醉的斑马  ·  [C#/VB.NET] C# 与 ...·  3 年前    · 
非常酷的冲锋衣  ·  groovy no such ...·  3 年前    · 

获取线程池队列当前的大小

如果你使用的是 Java 的线程池,那么你可以使用以下方法来检索线程池队列的当前大小:

Executor executor = ...;
if (executor instanceof ThreadPoolExecutor) {
    ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
    int queueSize = threadPoolExecutor.getQueue().size();
    System.out.println("Queue size: " + queueSize);

这里,我们将 Executor 实例转换为 ThreadPoolExecutor 实例,然后使用 getQueue() 方法获取队列,最后使用 size() 方法获取队列的大小。

  •