interrupt()不起作用

Ori*_*ski 8 java concurrency multithreading interrupt

我试图在以下代码中终止线程:

public synchronized void run() {
    try {
        while (!Thread.currentThread().isInterrupted()) {
            this.scan();
            this.distribute();
            this.wait();
        }
    } catch (InterruptedException e) {}
}

public void cancel() {
    this.interrupt();
}
Run Code Online (Sandbox Code Playgroud)

但线程不会终止.我使用了调试器并发现在命令之后this.interrupt(),线程没有被中断(我对表达式进行了监视this.isInterrupted()并保持不变false).任何人都知道为什么这个线程不会被打断?

编辑:

问题已经找到.原来这个帖子有两个实例.我附上导致这个问题的有问题的代码:

/* (class Detector extends Thread) */
Detector detector = new Detector(board);
...
Thread tdetector  = new Thread(detector); /* WRONG!!! */
...
tdetector.start();
...
Run Code Online (Sandbox Code Playgroud)

Ted*_*opp 5

根据文档,如果interrupt()在线程处于某种wait()状态时调用,则不会设置中断标志.您应该获得一个中断的异常,它将退出循环(和线程).

编辑

根据我的评论和您的回复,问题是您运行了多个这些线程.