如下所示,interrupted()会改变线程的中断状态(清除),而isInterrupted()不影响线程的中断状态

 
    /** * Tests whether the current thread has been interrupted.  The 
* <i>interrupted status</i> of the thread is cleared by this method. In
* other words, if this method were to be called twice in succession, the
* second call would return false (unless the current thread were
* interrupted again, after the first call had cleared its interrupted
* status and before the second call had examined it).
* * <p>A thread interruption ignored because a thread was not alive
* at the time of the interrupt will be reflected by this method
* returning false.
* * @return <code>true</code> if the current thread has been interrupted;
* <code>false</code> otherwise. * @see #isInterrupted() * @revised 6.0 */ public static boolean interrupted() {
return currentThread().isInterrupted(true);
} /** * Tests whether this thread has been interrupted. The <i>interrupted
* status</i> of the thread is unaffected by this method.
* * <p>A thread interruption ignored because a thread was not alive
* at the time of the interrupt will be reflected by this method
* returning false. * * @return <code>true</code> if this thread has been interrupted;
* <code>false</code> otherwise. * @see #interrupted() * @revised 6.0 */ public boolean isInterrupted()
{ return isInterrupted(false);} /** * Tests if some Thread has been interrupted. The interrupted state
* is reset or not based on the value of ClearInterrupted that is * passed. */ private native boolean isInterrupted(boolean ClearInterrupted);

Thread类的interrupted方法和isInterrupted方法的区别的更多相关文章

  1. StringBuffer类的delete()方法和deleteCharAt()方法的区别

    引言 StringBuffer类的delete()方法和deleteCharAt()方法都是用来删除StringBuffer字符串中的字符 区别 1.对于delete(int start,int en ...

  2. 并发基础篇(六):线程Thread类的start()方法和run()方法【转载】

    [转载] 一.初识java的线程是通过java.lang.Thread类来实现的.VM启动时会有一个由主方法所定义的线程.可以通过创建Thread的实例来创建新的线程.每个线程都是通过某个特定Thre ...

  3. Java Thread中,run方法和start方法的区别

     两种方法的区别: 1.start方法 用 start方法来启动线程,是真正实现了多线程, 通过调用Thread类的start()方法来启动一个线程,这时此线程处于就绪(可运行)状态,并没有运行,一旦 ...

  4. Thread中,run方法和start方法的区别

    1. 通过调用Thread类中的start()方法可以启动一个线程,但是线程并不是立刻运行,而是处于就绪态,一旦获取cpu时间片,则会立即运行run()方法 2. start()方法实现了多线程运行, ...

  5. Scanner类的next()方法和nextLine()方法的区别(简)

    1.  空白符:回车.空格.tab等 2.  next()方法读取到空白符就结束 3. nextLine()方法读取到回车结束,也就是 "\r"

  6. 【高并发】又一个朋友面试栽在了Thread类的stop()方法和interrupt()方法上!

    写在前面 新一轮的面试已经过去,可能是疫情的原因吧,很多童鞋纷纷留言说今年的面试题难度又提高了,尤其是对并发编程的知识.我细想了下,也许有那么点疫情的原因吧,但无论面试的套路怎么变,只要掌握了核心知识 ...

  7. sleep()方法和wait()方法的区别? sleep()方法和yield()方法的区别?

    sleep()方法和wait()方法的区别? sleep方法是Thread的静态方法,wait方法是Object类的普通方法 sleep方法不释放同步锁,wait方法释放同步锁(执行notify方法唤 ...

  8. ThinkPHP的D方法和M方法的区别

    M方法和D方法的区别 ThinkPHP 中M方法和D方法都用于实例化一个模型类,M方法 用于高效实例化一个基础模型类,而 D方法 用于实例化一个用户定义模型类. 使用M方法 如果是如下情况,请考虑使用 ...

  9. M方法和D方法的区别

    M方法和D方法的区别 ThinkPHP 中M方法和D方法都用于实例化一个模型类,M方法 用于高效实例化一个基础模型类,而 D方法 用于实例化一个用户定义模型类. 使用M方法 如果是如下情况,请考虑使用 ...

随机推荐

  1. LCA - 倍增法去求第几个节点

    You are given a tree (an undirected acyclic connected graph) with N nodes, and edges numbered 1, 2, ...

  2. 深入理解es6中的Promise

    https://www.jianshu.com/p/9e4af5b77253 https://zhuanlan.zhihu.com/p/30797777 https://segmentfault.co ...

  3. Jenkins 应用

    一.Jenkins Linux shell集成 新建任务 shell-freestyle-job,选择Freestyle project,点击[确定] ​ 添加描述,This is my first ...

  4. kaggle预测房价的代码步骤

    # -*- coding: utf-8 -*- """ Created on Sat Oct 20 14:03:05 2018 @author: 12958 " ...

  5. restframework 视图

    重要知识点 as_view()获取的是view方法名,当url配版成功,执行view方法 一.逻辑封装(mixins, generics) path('author/', views.AuthorVi ...

  6. Java入门 - 语言基础 - 02.开发环境配置

    原文地址:http://www.work100.net/training/java-environment-setup.html 更多教程:光束云 - 免费课程 开发环境配置 序号 文内章节 视频 1 ...

  7. 异数OS-织梦师-异数OS虚拟容器交换机(七) 走进4Tbps网络应用时代,加速5G应用真正落地

    . 异数OS-织梦师-异数OS虚拟容器交换机(七) 走进4Tbps网络应用时代,加速5G应用真正落地 本文来自异数OS社区 github: https://github.com/yds086/Here ...

  8. 编写python程序读入1到100之间的整数,然后计算每个数出现的次数,输入0表示结束输人,输入数据不包括0。如果数出现的大现如果大于1,输出时使用复数times

    #-*- coding:UTF-8 -*- #环境:python3 print("Enter the numbers between 1 and 100:") enterList= ...

  9. vuex 基本语法

    VUEX 的核心概念 1 .State (常用):2.Getters :3.Mutations(常用):4.Actions :5.Modules: 1.State是唯一的数据源,单一的状态树 cons ...

  10. python读取txt打印(print)出乱码的问题

    如下图所示,print第一行首位出现乱码的问题 网上的解答是因为UTF-8的BOM前缀(\xef\xbb\xbf) 解决这个问题的方法很多,最快捷的方法是txt文本另存为的时候更改编码格式 将txt另 ...