首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

[]一个线程的简单有关问题

2012-01-19 
[求助]一个线程的简单问题为什么我用了interrupt之后线程不会停止,API上说可以中断线程的啊。代码如下:publ

[求助]一个线程的简单问题
为什么我用了interrupt之后线程不会停止,API上说可以中断线程的啊。代码如下:

public   class   dfdfdfdf   extends   JFrame   {

dfdfdfdf(){
final   Thread   th=new   Thread(new   Runnable(){
public   void   run(){
while(true){
System.out.println( "* ");
}
}
});
JButton   b=new   JButton( "OK ");
add(b);
pack();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b.addActionListener(new   ActionListener(){
public   void   actionPerformed(ActionEvent   e){
th.interrupt();
}
});
th.start();
}

public   static   void   main(String[]   args)   {
new   dfdfdfdf();
}

}

[解决办法]
发送中断信号 不表示马上就中止线程
一般要中止线程,最好在线程内部用return

热点排行