久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

java isInterrupted()判斷線程的實例講解

瀏覽:4日期:2022-08-13 09:44:38
1、說明

isInterrupted()可以判斷當前線程是否被中斷,僅僅是對interrupt()標識的一個判斷,并不會影響標識發生任何改變(因為調用interrupt()的時候會設置內部的一個叫interrupt flag的標識)。

2、實例

public static void main(String[] args) throws InterruptedException{ Thread thread = new Thread(()->{while (true){} }); thread.start(); TimeUnit.SECONDS.sleep(1); System.out.println('Thread is interrupted :'+thread.isInterrupted()); thread.interrupt(); System.out.println('Thread is interrupted :'+thread.isInterrupted());}

實例擴展補充:

ublic class t12 { public static void main(String[] args) {try { MyThread12 thread = new MyThread12(); thread.start(); Thread.sleep(500); thread.interrupt(); System.out.println('是否終止1? =' + thread.interrupted()); System.out.println('是否終止2? =' + thread.interrupted());} catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace();}System.out.println('-------------end-------------'); }}class MyThread12 extends Thread { public void run() {for (int i = 0; i < 50000; i++) { System.out.println('i = ' + i);} }}

到此這篇關于java isInterrupted()判斷線程的實例講解的文章就介紹到這了,更多相關java isInterrupted()如何判斷線程內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Java
相關文章:
主站蜘蛛池模板: 蓬溪县| 龙胜| 绍兴市| 高雄县| 保康县| 金乡县| 黔西| 紫金县| 秦皇岛市| 龙岩市| 彭水| 山东省| 同江市| 溧水县| 贞丰县| 河北区| 喀喇| 嘉鱼县| 福建省| 溆浦县| 铜梁县| 乡城县| 都昌县| 平乐县| 政和县| 安阳县| 平凉市| 苍南县| 永昌县| 昌宁县| 小金县| 全州县| 永安市| 双城市| 托克逊县| 沙洋县| 育儿| 金溪县| 普安县| 宁武县| 吕梁市|