国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

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

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

isInterrupted()可以判斷當(dāng)前線程是否被中斷,僅僅是對interrupt()標(biāo)識的一個(gè)判斷,并不會(huì)影響標(biāo)識發(fā)生任何改變(因?yàn)檎{(diào)用interrupt()的時(shí)候會(huì)設(shè)置內(nèi)部的一個(gè)叫interrupt flag的標(biāo)識)。

2、實(shí)例

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());}

實(shí)例擴(kuò)展補(bǔ)充:

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);} }}

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

標(biāo)簽: Java
相關(guān)文章:
主站蜘蛛池模板: 桃园县| 商都县| 剑河县| 翁源县| 潢川县| 马关县| 瑞金市| 临沂市| 渭源县| 石棉县| 辽中县| 秦皇岛市| 望都县| 南开区| 延安市| 高邮市| 东乡族自治县| 涿鹿县| 兴海县| 南安市| 周至县| 秦皇岛市| 凤冈县| 梓潼县| 定州市| 额尔古纳市| 荥经县| 夏津县| 遂平县| 绵阳市| 荥经县| 新民市| 阳原县| 仁布县| 虞城县| 南郑县| 满洲里市| 理塘县| 大余县| 江安县| 山东|