有一个start函数,里面有一堆线程,在main里调用这个函数什么问题都没有,现在加了一个button
用这段代码调用函数,一点按扭就奇慢无比,如同死机
 Button bStart=new Button("开始获取");
 bStart.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        System.out.println("ActionEvent" + e);
        start();
      }
    });
add(bStart);
如果不调用start就什么事都没有,郁闷!

解决方案 »

  1.   

    start()是线程的start方法,还是你自己写的start
    主要看你在执行start()时都做了些什么
      

  2.   

    以前你用的是单线程现在按钮事件中新开一个线程(继承Thread后重写public void run()方法),用新的线程去进行计算,这样就不影响你界面上其它组件的操作了。
      

  3.   

    Update the start methods using the following statements, replace the comments with your codes.private void start(){
     new Thread(){
      public void run(){
    //    ...
    //    Your business codes    
    //    ...
      }
     }.start();
    }
      

  4.   

    zhuang_zi(庄子) ,还是不行啊
    我在run 里是这么写的
    public void run(){
      long i=0;
        while (i<1000000000){
    i++;}
        System.out.println("ssss");
    }
      }.start();
    在运行的时候界面还是死掉的。
      

  5.   

    你让这个线程先睡一下子....我试过类似方法,没有什么问题啊.
    private void start(){
    new Thread(){
    public void run(){
    // ...
    // Your business codes
    try{
     Thread.sleep(500);
    }catch(Exception e){
    }
    long i=0;
    while (i<1000000000){
    i++;
    }
    System.out.println("ssss");
    // ...
    }
    }.start();
    }
      

  6.   

    sleep在while循环外应该没什么作用吧,我是怕死机写了while (i<1000000000),否则就写while(true)了。不过换了一台快一点的机器似乎就没问题了,既然是多线程慢机器cpu也应该轮流调度啊,不应该死,看来不能轻易在破机器上试多线程了。