此方式创建线程池
ExecutorService es = Executors.newCachedThreadPool();
希望能监控线程池的状况。

解决方案 »

  1.   

    多看看API看有没有有用的方法,我是没找到对这个类不熟悉,没用过
    还是来顶顶
      

  2.   

    Executors.newCachedThreadPool()的源代码是
        public static ExecutorService newCachedThreadPool() {
            return new ThreadPoolExecutor(0, Integer.MAX_VALUE,
                                          60L, TimeUnit.SECONDS,
                                          new SynchronousQueue<Runnable>());
        }
    就是说,返回的是子类对象ThreadPoolExecutor的实例,
    而ThreadPoolExecutor类提供了getPoolsize(),getActiveCount()等方法...
    将你的es强制类型转换成ThreadPoolExecutor吧
      

  3.   


    这样可以了。谢谢  
    不过很悲剧的是 mina2中的ExecutorFilter线程池使用的是
    OrderedThreadPoolExecutor继承ThreadPoolExecutor类
    但是getQueue方法被禁止使用,源码如下
    public BlockingQueue<Runnable> getQueue() {
      throw new UnsupportedOperationException();
    }