java中一个子线程如何通过interrupt手段来停止另外一个子线程

下面给出了一个子线程通过interrupt手段,来停止另外一个子线程的例子。 

例:1.5.2_2

class ThreadMark_to_win extends Thread {
    Thread st1;
    public void run() {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            System.out.println("我是子线程,被打断");
        }
        st1.interrupt();
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            System.out.println("我是子线程,第二次睡时被打断");
            return;
        }
    }
    public void setSilblingThread1(Thread t1) {
        st1 = t1;

更多内容请见原文,文章转载自:https://blog.csdn.net/qq_44639795/article/details/103096856

posted @ 2021-04-06 08:46  小龙虾1  阅读(185)  评论(0)    收藏  举报