是否可以在java调试中从外部完成线程?

是否可以在java调试中从外部完成线程?,java,multithreading,debugging,netbeans,netbeans-7,Java,Multithreading,Debugging,Netbeans,Netbeans 7,我想知道是否有可能在调试中外部完成一个线程(我不介意使用不推荐的thread.stop()以不安全的方式) 我使用的是Netbeans 7.1.2,线程调试的选项有make current、suspend、interrupt,但没有stop选项。您可以用这个代替thread.stop()方法 当您想要停止线程调用stopThread()函数时,如上例所示。@assylias interrupt仅在线程处于睡眠、等待、加入或可中断通道时才起作用,而在其他情况下则不起作用。我认为唯一的替代方法是通过

我想知道是否有可能在调试中外部完成一个线程(我不介意使用不推荐的thread.stop()以不安全的方式)


我使用的是Netbeans 7.1.2,线程调试的选项有make current、suspend、interrupt,但没有stop选项。

您可以用这个代替thread.stop()方法


当您想要停止线程调用stopThread()函数时,如上例所示。

@assylias interrupt仅在线程处于睡眠、等待、加入或可中断通道时才起作用,而在其他情况下则不起作用。我认为唯一的替代方法是通过编程实现。我不知道这是IDE限制还是JDK(缺乏)特性,你几乎可以随时捕捉到中断。如果您在运行函数中循环,比如使用
while
循环,您可以检查中断标志作为循环条件或循环中的某个位置。如果您正在调用诸如queue.put(…)之类的阻塞函数,它们都会在中断时抛出InterruptedException。@goblinjuice我想在不更改代码的情况下调试它,但我理解您的意思
class TestThread implements Runnable{

 private Thread thread;

 public TestThread()
 {
   thread=new Thread(this);
 }

 public void stopThread()
 {
   thread=null;
 } 
 public void run()
 {
   while(thread!=null)
   {
     //Some Code here
   }
 }
}

class Main
{
   public static void main(String args[])
   {
     TestThread tt=new TestThread();
     //sleep for some time
     tt.stopThread();
   }
}