当前位置:网站首页>Multithread interrupt usage
Multithread interrupt usage
2022-06-22 03:52:00 【Max constant】
Two knowledge points involved in this paper
- interrupt() : Interrupt thread
If the interrupted thread is sleep,wait,join Can cause interruption The thread threw InterruptedException, And get rid of Interrupt mark remember
; If you interrupt a running thread , Will set up Interrupt mark remember ;park Thread interrupted , It will also set up Break mark
- isInterrupted(): Determine whether the current thread is interrupted
Will clear Break mark
Sample code
public class interrupt usage {
public static void main(String[] args) throws InterruptedException {
Thread t1 = new Thread(() -> {
while (true) {
boolean interrupted = Thread.currentThread().isInterrupted();
if (interrupted){
System.out.println(" Interrupted , Exit loop ");
break;
}else {
System.out.println(" Normal execution is not interrupted --");
}
}
}, "t1");
t1.start();
Thread.sleep(100);
System.out.println(" Start interrupt");
t1.interrupt();
}
}

When the thread sleep is completed Thread.sleep(100), Here we go interrupt Interrupt thread , The method is then executed in the loop isInterrupted(), The return result is true, It means that the thread has been interrupted
边栏推荐
- 七千字详解阿里云新一代云计算体系架构 CIPU
- 1690. stone game vii- dynamic programming method
- 我在华为度过的 “两辈子”(学习那些在大厂表现优秀的人)
- L'avenir est venu: l'âge du nuage
- MySQL 45 lecture learning notes (IV) index
- docker 安装redis
- 快速掌握 ASP.NET 身份认证框架 Identity - 用户注册
- Resources for all projects
- Mysql 45讲学习笔记(三)SQL更新语句的执行
- 倍福CX9020(WINCE 7)控制器使用方法和操作
猜你喜欢

svn与cvs的区别有哪些

Seven thousand word explanation of Alibaba cloud's new generation cloud computing architecture cipu

A component required a bean of type 'com. example. demo3.service. UserServiceImp' that could not be fou

MySQL 45 lecture notes (I) execution of an SQL statement

docker 安装redis

3DE new simulation status

Ads communication between Beifu twincat3 controller and controller

面试官:知道 Flutter 生命周期吗?
![[schematic diagram and PCB] design of ultrasonic rangefinder based on single chip microcomputer](/img/84/45348dce0f5427837e53c92088cea7.png)
[schematic diagram and PCB] design of ultrasonic rangefinder based on single chip microcomputer

Balanced binary tree -- adjusting transformation rules
随机推荐
【BP回归预测】基于matlab GA优化BP回归预测(含优化前的对比)【含Matlab源码 1901期】
倍福TwinCAT 3 气缸动作程序编写
Flutter-Stream使用
L'avenir est venu: l'âge du nuage
Mysql 45讲学习笔记(一)一条sql语句的执行
Flyter color gradient and follow button imitating Taobao gradient
试用了多款报表工具,终于找到了基于.Net 6开发的一个了
Use of shutter stream
Shutter status management
In fact, many people are studying Electronics
How to randomly assign 1000 to 10 numbers
SSM住院管理系统
Dynamic planning - Taking stair climbing with minimum cost as an example
AI writes its own code to let agents evolve! The big model of openai has the flavor of "human thought"
IIR filter design basis and MATLAB design example
Mqtt of NLog custom target
【牛客刷题-SQL大厂面试真题】NO1.某音短视频
Code of ultrasonic rangefinder based on 51 (screenshot version)
[schematic diagram and PCB] design of ultrasonic rangefinder based on single chip microcomputer
How to install laravel