Thread aThread = new Thread(new ProcessorThread1());
aThread.start();

解决方案 »

  1.   

    以下是详细的代码,刚才说错了,编译能通过,不过运行时出错
    import java.net.*;
    import java.io.*;
    import java.lang.*;
    import java.util.*;
     public class ProcessorThread1 implements Runnable {
    private Thread mTdThread[];
    private static int mintThreadCount=0;
    static int mintWait=0;     //空闲线程总数
    static  int mintBusy=0;    //运行线程总数
    static int mintCount=0;    //数据接受线程总数
    static String mstrSubstt="";
    static  int mintDd;        //用于引用ReqUDPPortListener类中要求线程个数的变量
    static  int mintMid;       //用于比较的中间变量
    static DataPool mdpPool=ReqUDPPortListener.mdpPool;
                       //用于引用ReqUDPPortListener类中数据池的堆栈   
        public void threadNew() 
        {
    mintThreadCount++;    
    mTdThread[mintThreadCount]=new Thread(this);
    System.out.println("新线程:"+mintThreadCount+"建立");
    mintWait++;
    System.out.println("现有空闲线成数目为:"+mintWait);
    System.out.println("现有运行状态线程数目为:"+mintBusy);
    System.out.println("现有各状态线程总数为:"+mintThreadCount);
    }
        public void threadStart() 
        {
    mTdThread[mintThreadCount].start();
    System.out.println("线程:"+mintThreadCount+"启动");
    mintWait--;
    mintBusy++;
    System.out.println("现有空闲线成数目为:"+mintWait);
    System.out.println("现有运行状态线程数目为:"+mintBusy);
    System.out.println("现有各状态线程总数为:"+mintThreadCount);
    }
        public void threadWait()
        {
    }
        public void threadDestroy()
        {
    }
        public void run()
        {
         System.out.println("aaaaaaaaaaa");
    }                             
        public static void main(String [] arguments) 
        {
         ProcessorThread1 dd=new ProcessorThread1();
         dd.threadStart();
        }
      

  2.   

    public class ProcessorThread1 implements Runnable {
        private Thread mTdThread[];
        private static int mintThreadCount=0;
    public void start () {
             mTdThread[mintThreadCount]=new Thread(this);   
    mTdThread[mintThreadCount].start();
               
        }
     public void run() 
    {
    System.out.println("fsa");
    }
    }
      

  3.   

    建议不要用this,还是写明好一些也方便维护
      

  4.   

    不写this,写明了,也不行,我刚试过
      

  5.   

    给你修改后的,可以运行的:
    public class ProcessorThread1 implements Runnable {
        private Thread mTdThread[]=new Thread[3];//这里有初始化数组
        private static int mintThreadCount=0;
    public static void main(String[] a){
       ProcessorThread1 b=new  ProcessorThread1();
       b.start();
    }
    public void start () {    mTdThread[mintThreadCount]=new Thread(new ProcessorThread1());   
    mTdThread[mintThreadCount].start();
               
        }
     public void run() 
    {
    System.out.println("fsa");
    }
    }记住:数组必须初始化后才能使用,不然出现空指针异常。
      

  6.   

    上面运行后的输出结果:---------- java ----------
    fsa
    Normal Termination
    Output completed (0 sec consumed).
      

  7.   

    这是我修改过的程序,编译通过了:可是仍然有空指针异常
    import java.net.*;
    import java.io.*;
    import java.lang.*;
    import java.util.*;
     public class ProcessorThread1 implements Runnable {
    private Thread mTdThread[]=new Thread [1000];
    private static int mintThreadCount=0;
    static int mintWait=0;     //空闲线程总数
    static  int mintBusy=0;    //运行线程总数
    static int mintCount=0;    //数据接受线程总数
    static String mstrSubstt="";
    static  int mintDd;        //用于引用ReqUDPPortListener类中要求线程个数的变量
    static  int mintMid;       //用于比较的中间变量
    static DataPool mdpPool=ReqUDPPortListener.mdpPool;
                       //用于引用ReqUDPPortListener类中数据池的堆栈   
        public void threadNew() 
        {
    mintThreadCount++;    
    mTdThread[mintThreadCount]=new Thread(new ProcessorThread1());
    System.out.println("新线程:"+mintThreadCount+"建立");
    mintWait++;
    System.out.println("现有空闲线成数目为:"+mintWait);
    System.out.println("现有运行状态线程数目为:"+mintBusy);
    System.out.println("现有各状态线程总数为:"+mintThreadCount);
    }
        public void start() 
        {
    mTdThread[mintThreadCount].start();
    System.out.println("线程:"+mintThreadCount+"启动");
    mintWait--;
    mintBusy++;
    System.out.println("现有空闲线成数目为:"+mintWait);
    System.out.println("现有运行状态线程数目为:"+mintBusy);
    System.out.println("现有各状态线程总数为:"+mintThreadCount);
    }
        public void threadWait()
        {
    }
        public void threadDestroy()
        {
    }
        public void run()
        {
         System.out.println("aaaaaaaaaaa");
    }                             
        public static void main(String [] arguments) 
        {
         ProcessorThread1 dd=new ProcessorThread1();
         dd.start();
        }
      

  8.   

    threadStart() 这个函数谁调用的,你的构造函数呢
      

  9.   

    对不起是public void threadNew() 这个函数谁调用的,你的构造函数呢
    刚才打错了
      

  10.   

    to:shanmao(山猫) \wjmmml(笑着悲伤) :谢谢你们,我的问题找到了,谢谢,接分吧