Thread类的interrupted方法和isInterrupted方法的区别
如下所示,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方法的区别的更多相关文章
- StringBuffer类的delete()方法和deleteCharAt()方法的区别
引言 StringBuffer类的delete()方法和deleteCharAt()方法都是用来删除StringBuffer字符串中的字符 区别 1.对于delete(int start,int en ...
- 并发基础篇(六):线程Thread类的start()方法和run()方法【转载】
[转载] 一.初识java的线程是通过java.lang.Thread类来实现的.VM启动时会有一个由主方法所定义的线程.可以通过创建Thread的实例来创建新的线程.每个线程都是通过某个特定Thre ...
- Java Thread中,run方法和start方法的区别
两种方法的区别: 1.start方法 用 start方法来启动线程,是真正实现了多线程, 通过调用Thread类的start()方法来启动一个线程,这时此线程处于就绪(可运行)状态,并没有运行,一旦 ...
- Thread中,run方法和start方法的区别
1. 通过调用Thread类中的start()方法可以启动一个线程,但是线程并不是立刻运行,而是处于就绪态,一旦获取cpu时间片,则会立即运行run()方法 2. start()方法实现了多线程运行, ...
- Scanner类的next()方法和nextLine()方法的区别(简)
1. 空白符:回车.空格.tab等 2. next()方法读取到空白符就结束 3. nextLine()方法读取到回车结束,也就是 "\r"
- 【高并发】又一个朋友面试栽在了Thread类的stop()方法和interrupt()方法上!
写在前面 新一轮的面试已经过去,可能是疫情的原因吧,很多童鞋纷纷留言说今年的面试题难度又提高了,尤其是对并发编程的知识.我细想了下,也许有那么点疫情的原因吧,但无论面试的套路怎么变,只要掌握了核心知识 ...
- sleep()方法和wait()方法的区别? sleep()方法和yield()方法的区别?
sleep()方法和wait()方法的区别? sleep方法是Thread的静态方法,wait方法是Object类的普通方法 sleep方法不释放同步锁,wait方法释放同步锁(执行notify方法唤 ...
- ThinkPHP的D方法和M方法的区别
M方法和D方法的区别 ThinkPHP 中M方法和D方法都用于实例化一个模型类,M方法 用于高效实例化一个基础模型类,而 D方法 用于实例化一个用户定义模型类. 使用M方法 如果是如下情况,请考虑使用 ...
- M方法和D方法的区别
M方法和D方法的区别 ThinkPHP 中M方法和D方法都用于实例化一个模型类,M方法 用于高效实例化一个基础模型类,而 D方法 用于实例化一个用户定义模型类. 使用M方法 如果是如下情况,请考虑使用 ...
随机推荐
- Linux上的Tomcat地址映射,且404错误解决
问题:现在想要加一个下载文件功能,但是文件地址不在tomcat的webapps下,需要通过地址映射到tomcat下面再通过链接执行下载文件功能. 解决方法有两种: 方法一: 用方法一的前提是不用启动服 ...
- Serverless 微服务实践-移动应用包分发服务
背景 阿里云函数计算是事件驱动的全托管计算服务.通过函数计算,您无需管理服务器等基础设施,只需编写代码并上传.函数计算会为您准备好计算资源,以弹性.可靠的方式运行您的代码,并提供日志查询.性能监控.报 ...
- Pandas的介绍与基本使用
1.什么是Pandas 当大家谈论到数据分析时,提及最多的语言就是Python和SQL,而Python之所以适合做数据分析,就是因为他有很多强大的第三方库来协助,pandas就是其中之一,它是基于Nu ...
- poj 2689 区间素数筛
The branch of mathematics called number theory is about properties of numbers. One of the areas that ...
- 继承Exception⭐⭐
public class ECOrderException : Exception { //第一种类型: throw new ECOrderException { ErrorCode = " ...
- objectarx 按比例分割封闭多段线
测试结果:这个是按0.1,0.1,0.1,0.3,0.4的比例划分的. 插件描述:这个插件主要是选择一个多段线poly,设置poly的close属性为true,在poly任意一侧画一条长线line(l ...
- springboot 报错nested exception is java.lang.IllegalStateException: Failed to check the status of the service xxxService No provider available for the service
spring: dubbo:#关闭所有服务的启动时检查:(没有提供者时报错) consumer: check: false timeout: 3000
- Myeclipse 2017 下载+安装+激活+集成配置【JRE 8+Tomcat 9+MySQL 5.7.29】
Myeclipse 2017 的下载 Myeclipse 2017 下载地址:https://www.jianguoyun.com/p/DTEBo1cQ6LnsBxj9984C Myeclipse 2 ...
- 第一章001-003课程介绍、计算机网络概述、Internet概述
计算机网络概述 课程安排: 第一章:概述 第二章:物理层 第三章:数据链路层 第四章:网络层 第五章:运输层 第六章:应用层 第七章:网络安全 第八章:因特网上的音频/视频服务 第九章:无线网络 第十 ...
- 软工造梦厂团队项目(Alpha版本发布2)
课程 (https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience) 作业要求 https://www.cnblogs.com/h ...