如何在java中使用isInterrupted()函数判断线程

  介绍

这期内容当中小编将会给大家带来有关如何在java中使用isInterrupted()函数判断线程,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

java有哪些集合类

java中的集合主要分为四类:1,列清单表:有序的,可重复的;2、队列队列:有序,可重复的;3,设置集合:不可重复;4、地图映射:无序,键唯一,值不唯一。

1,说明

isInterrupted()可以判断当前线程是否被中断,仅仅是对中断()标识的一个判断,并不会影响标识发生任何改变(因为调用中断()的时候会设置内部的一个叫中断标志的标识)。

2,实例

public  static  void  main (String [], args), throws  InterruptedException {   ,,,Thread  Thread =, new 线程(()→{   ,,,,,,,while (真正的){}   ,,,});   ,,,thread.start ();   ,,,TimeUnit.SECONDS.sleep (1);   ,,,System.out.println (“Thread  is  interrupted :“+通过());   ,,,thread.interrupt ();   ,,,System.out.println (“Thread  is  interrupted :“+通过());   }

实例扩展补充:

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 块   ,,,,,,,,,,,e.printStackTrace ();   ,,,,,,,}   ,,,,,,,System.out.println(“- - - - - - - - - - - -端- - - - - - - - - - - -产生绯闻;);   ,,,}   }      class  MyThread12  extends  Thread  {   ,,,public  void 运行(),{   ,,,,,,,for  (int 小姐:=,0;,小姐:& lt;, 50000;,我+ +),{   ,,,,,,,,,,,System.out.println(“小姐:=,,,+,i);   ,,,,,,,}   ,,,}   }

上述就是小编为大家分享的如何在java中使用isInterrupted()函数判断线程了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。

如何在java中使用isInterrupted()函数判断线程