当前位置:网站首页>Thread status and stop
Thread status and stop
2022-06-26 05:59:00 【Mr.Rop】
Thread state

Thread stop
public class TestStop implements Runnable {
// 1. Set a flag bit
private boolean flag = true;
@Override
public void run() {
int i = 0;
while (flag){
System.out.println("run....Thread"+i++);
}
}
// 2. Set an open method to stop the thread , Conversion flag bit
public void stop(){
this.flag = false;
}
public static void main(String[] args) {
TestStop testStop = new TestStop();
new Thread(testStop).start();
for (int i = 0; i < 1000; i++) {
System.out.println("main"+i);
if (i == 900){
testStop.stop();
System.out.println(" It's time for the thread to stop ");
}
}
}
}
边栏推荐
- Getting started with Python
- Class and object learning
- 花生壳内网穿透映射NPM私服问题
- 423- binary tree (110. balanced binary tree, 257. all paths of binary tree, 100. same tree, 404. sum of left leaves)
- 跨域的五种解决方案
- Posting - don't get lost in the ocean of Technology
- Pytorch (network model training)
- How to associate wechat applet QR code to realize two code aggregation
- COW读写复制机制在Linux,Redis ,文件系统中的应用
- REUSE_ ALV_ GRID_ Display event implementation (data_changed)
猜你喜欢

小程序如何关联微信小程序二维码,实现二码聚合

On site commissioning - final method of kb4474419 for win7 x64 installation and vs2017 flash back

组合模式、透明方式和安全方式

REUSE_ALV_GRID_DISPLAY 事件实现(DATA_CHANGED)

Adapter mode

家庭记账程序(第二版 加入了循环)

状态模式,身随心变
Posting - don't get lost in the ocean of Technology

How Navicat reuses the current connection information to another computer

Household accounting procedures (First Edition)
随机推荐
numpy. exp()
Factory method pattern, abstract factory pattern
Redis底层数据结构
类和对象的学习
numpy.log
421- binary tree (226. reversed binary tree, 101. symmetric binary tree, 104. maximum depth of binary tree, 222. number of nodes of complete binary tree)
MySQL-06
Some doubts about ARP deception experiment
Gram matrix
REUSE_ ALV_ GRID_ Display event implementation (data_changed)
Pre-Sale Analysis
NPM private server problem of peanut shell intranet penetration mapping
numpy.tile()
Force buckle 875 Coco, who likes bananas
Test depends on abstraction and does not depend on concrete
How to use the tablet as the second extended screen of the PC
Solve the problem that Cmdr cannot use find command under win10
SQL query time period content
one billion two hundred and twelve million three hundred and twelve thousand three hundred and twenty-one
DOM document