4个进程?你是不是还运行着别的java程序呀?
这个程序只有3个线程~
我在我机上试过了
一条主线程跟你创建的tp1,tp2线程Thread.activeCount()
Returns the number of active threads in the current thread's thread group.默认的是系统线程组,你线程组里是不是有有其他程序的线程?

解决方案 »

  1.   

    修改了一下,大家运行一下看看结果
    import java.util.*; 
    class TimePrinter extends Thread { 
    int pauseTime; 
    String name; 
    public TimePrinter(int x, String n) { 
    pauseTime = x; 
    name = n; 

    public void run() { 
    while(true) 

    try { 
    System.out.println(name + ":" + new 
    Date(System.currentTimeMillis())); 
    Thread.sleep(pauseTime); 
    get();
    } catch(Exception e)

    System.out.println(e); 



    static public void main(String args[]) { 
    TimePrinter tp1 = new TimePrinter(1000, "Fast Guy"); TimePrinter tp2 = new TimePrinter(5000, "Slow Guy"); tp2.start(); 
    tp1.start(); 
    //
    Thread[] array = new Thread [10];
    int i = Thread.enumerate( array );
    for (int j=0 ; j< i ; j++)
    {
    System.out.println( "------------" + array[j].getName());
    } System.out.println("------------" + Thread.activeCount());
    //} private void get()
    {
    Thread[] array = new Thread [10];
    int i = Thread.enumerate( array );
    for (int j=0 ; j< i ; j++)
    {
    System.out.println( "------------" + array[j].getName());
    } System.out.println("------------" + Thread.activeCount());}
    } ==============================================================我的运行结果是:D:\csdn_test>java TimePrinter
    ------------main
    ------------Thread-1
    ------------Thread-2
    ------------4
    Fast Guy:Mon Apr 26 11:01:59 CST 2004
    Slow Guy:Mon Apr 26 11:01:59 CST 2004
    ------------Thread-1
    ------------Thread-2
    ------------DestroyJavaVM
    ------------4
    Fast Guy:Mon Apr 26 11:02:00 CST 2004
    ------------Thread-1
    ------------Thread-2
    ------------DestroyJavaVM
    ------------4
      

  2.   

    每一次显示都是说有4个线程,但是只给出了和main thread在同一个group中的3个,另外一个我不知道怎么获取,应当不是和main thread一组的,我猜想是不是垃圾回收线程呢? DestroyJavaVM是什么线程?“精灵线程”是什么啊?