jdk1.3以后就不提倡使用强行结束线程的方法,你应该尽量使线程正常退出run方法,如果想调整他们的顺序,可以通过调整线程的优先级来控制

解决方案 »

  1.   

    用RUN,设置个FLAG标志,当检测到FLAG为FALSE的时候就让程序退出
      

  2.   

    其实正常的情况下,要这样去实现
    import javax.swing.*;
    import java.awt.event.*;
    public class Aaa extends JFrame implements ActionListener,Runnable 
    {
    Thread one;
    boolean flag=false;
    JButton jb1,jb2;
    JPanel jp;
    public Aaa()
    {
    jb1=new JButton("stop");
    jb2=new JButton("start");
    jp=new JPanel();
    jb1.addActionListener(this);
    jb2.addActionListener(this);
    jp.add(jb1);
    jp.add(jb2);
    getContentPane().add(jp);
    setSize(300,300);
    setVisible(true);
    one=new Thread(this);
    one.start();
    }
    public void actionPerformed(ActionEvent evt)
    {
    Object obj=evt.getSource();
    if(obj==jb1)
    {
    flag=true;
    }
    else if(obj==jb2)
    {
    flag=false;
    Thread th=new Thread(this);
    th.start();
    }
    }
    public void run()
    {
    while(true)
    {
    System.out.print("1");
    if(flag==true)
    break;
    try{Thread.currentThread().sleep(500);}
    catch(InterruptedException ie){}
    }
    }
    public static void main(String args[])
    {
    new Aaa();
    }
    }
      

  3.   

    其实,线程的run方法运行结束,就是线程的自然终结。
    别的就没有什么好讲的了,呵呵。