有些方法内部实现会启用线程的,比如swing有可能在画图时会启用线程,特别是用到某些第三方的库,timer也是要产生线程的。

解决方案 »

  1.   

    老乡,你把活动中的线程都列印出来不就清楚了,我给你把Server.java改了一下,你一运行就明白了,为了能更好的测试,你在User.java中s = new Socket("127.0.0.1",prot);后面加上Thread.sleep(60000);这样就可以测试几个User同时登陆了。import java.io.*;
    import java.net.*;public class Server {
      ServerSocket ss;
      Thread [] t;
      final int prot = 6666;  public Server() {
        try {
          ss = new ServerSocket(prot);
          System.out.println("服务器已经启动......");
        }
        catch (IOException ex) {
          System.out.println("无法启动......");
        }
      }
      public void socket() throws IOException {
        while(true){
          Socket s = ss.accept();
          ServerThread sTh = new ServerThread(s);
          t = new Thread[sTh.activeCount()];
          sTh.start();
          System.out.println("线程数:"+sTh.enumerate(t));
          for(int i=0;i<sTh.enumerate(t);i++){
            System.out.println(i+1+":"+t[i]);
          }
        }
      }
      public static void main(String[] args) throws IOException {
        Server server = new Server();
        server.socket();
      }
    }<------ 树欲静而风不止 ------>
      

  2.   

    老兄,这个我看不太懂哦。
    Thread [] t = new Thread[sTh.activeCount()];好象是一个线程组
    为什么用sTh.enumerate(t)得到的数字和sTh.activeCount()不一样呢?
    将详细点撒,偶不明白啊
      

  3.   

    不懂。只能 UP 拣分了。up!