InterruptionInJava
Posted tonggc1668
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了InterruptionInJava相关的知识,希望对你有一定的参考价值。
package com.test; public class InterruptionInJava implements Runnable{ public static void main(String[] args) throws InterruptedException { Thread testThread = new Thread(new InterruptionInJava(),"InterruptionInJava"); //start thread testThread.start(); //interrupt thread testThread.interrupt(); System.out.println("main end"); } @Override public void run() { try { Thread.sleep(10000); } catch (InterruptedException e) { System.out.println(Thread.currentThread().isInterrupted()); Thread.currentThread().interrupt(); System.out.println(Thread.currentThread().isInterrupted()); } while(true){ if(Thread.currentThread().isInterrupted()){ System.out.println("Yes,I am interruted,but I am still running"); }else{ System.out.println("not yet interrupted"); } } } }
以上是关于InterruptionInJava的主要内容,如果未能解决你的问题,请参考以下文章