当前位置:网站首页>The difference between run and start in thread class
The difference between run and start in thread class
2022-07-24 04:53:00 【lzhNox】
Thread Class run and start The difference between
Let's first create a thread
Be careful : What is used here is start start-up t Threads , And our code here is inherited Thread rewrite run How to write
class MyThread2 extends Thread {
public void run() {
while(true) {
System.out.println("hello thread");
try {
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public class demo5 {
public static void main(String[] args) {
int a=0;
Thread t= new MyThread2();
t.start();
while(true) {
System.out.println("Hello");
}
}
}
After running , Use java Bring their own tools jconsole Check the progress :

Look for the ! At this time, there is a thread named Thread-0, This is the thread we created ourselves t.
Then we change the code just now , Change it to t.run();
And on again jconsole:

You will find that there is no thread we created in the thread
So we come to the following conclusion :
- Use start The thread can be started , Create a new thread , And will call internally Runnable Interface run Method
- Use run No new threads will be created , Instead, we executed in the previous thread run Content rewritten inside
边栏推荐
- Kingbase v8r6 cluster installation and deployment case - script online one click expansion
- Chapter VI more supervision training
- What if the computer desktop gets stuck? Introduction of solutions to computer crash and desktop jamming
- Godson leader spits bitterness: we have the world's first performance CPU, but unfortunately no one uses it!
- Web3 product manager's Guide: how to face the encryption world
- What is the general family of programmers working in first tier cities?
- OWA dynamic password SMS authentication scheme solves the problem of outlook email two factor authentication
- Little black gnawing leetcode:589. Preorder traversal of n-ary tree
- Unable to delete the file prompt the solution that the file cannot be deleted because the specified file cannot be found
- mapreduce概念
猜你喜欢

Clickpaas, a low code service provider, has completed a strategic merger with BiP technology to jointly build an industrial digital base

Kingbase V8R6集群安装部署案例---脚本在线一键扩容

Nautilus 3.19.2为Gnome增添动力

How much do you know about thread pool and its application

An online accident, I suddenly realized the essence of asynchrony

Array force buckle (continuously updated)

Chapter V communication training

一次线上事故,我顿悟了异步的精髓

"Paper reproduction" bidaf code implementation process (3) model establishment

Esp32 tutorial (I): vscode+platform and vscade+esp-idf
随机推荐
Excel cell formula - realize Ackerman function calculation
本,降低线上要度是一样的。发现异常实例cp操
pso和mfpso
How to play the Microsoft twin tool twinsonot? Introduction to twin test tool twinornot
Chapter III encog workbench
Unable to delete the file prompt the solution that the file cannot be deleted because the specified file cannot be found
Division of training set, verification set and test set in link prediction (take randomlinksplit of pyg as an example)
What if the computer desktop gets stuck? Introduction of solutions to computer crash and desktop jamming
Godson leader spits bitterness: we have the world's first performance CPU, but unfortunately no one uses it!
Middle aged crisis, workplace dad who dare not leave, how to face life's hesitation
How long has it been since you changed your cell phone?
[JDBC] error exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.communicationsexception: communica
Is it true to pay attention to official account and receive Xiaomi mobile power for free? Wechat circle of friends sends Xiaomi mobile power
Design of high frequency small signal resonant amplifier course design Multisim Simulation
Esp32:arduino tutorial summary
微信朋友圈的高性能架构设计
Common cross domain problems
C语言:冒泡排序法
Yolov7 -- brief introduction of the paper
Summary of common errors in wechat applet cloud development