请教大虾们,我要在java中监控应用程序中的线程是否在运行,请问该如何去做?谢谢各位不吝赐教。

解决方案 »

  1.   


    下面的静态方法可以用数组返回Java VM中当前运行的所有线程 
    public static Thread[] findAllThreads() { 
    ThreadGroup group =  
    Thread.currentThread().getThreadGroup(); 
    ThreadGroup topGroup = group; // 遍历线程组树,获取根线程组 
    while ( group != null ) { 
    topGroup = group; 
    group = group.getParent(); 

    // 激活的线程数加倍 
    int estimatedSize = topGroup.activeCount() * 2; 
    Thread[] slackList = new Thread[estimatedSize]; 
    //获取根线程组的所有线程 
    int actualSize = topGroup.enumerate(slackList); 
    // copy into a list that is the exact size 
    Thread[] list = new Thread[actualSize]; 
    System.arraycopy(slackList, 0, list, 0, actualSize); 
    return list; 
    } 这个么??
      

  2.   


    这个jdk自带的只适用于我们开发的吧?客户能看懂这个么??