当前位置:网站首页>Create a multithreaded thread class
Create a multithreaded thread class
2022-06-24 20:57:00 【Platonic】
How to create multithreaded programs : establish Tread Subclasses of classes
java.lang.Tread class : Is a class that describes threads , We want to implement more threaded programs , Must inherit Tread class
Implementation steps :
- Create a Tread Subclasses of classes ,
- stay Tread Class Tread Class run Method , Set up thread tasks
- Set up TRead Subclass object of class ,
- call Tread Methods in class start Method , Start a new thread , perform run Method
void start() Causes the thread to start executing :java The virtual machine calls the thread's run Method .
java The program belongs to preemptive scheduling , That thread has a high priority , That thread takes precedence , Same priority , Select any one to execute .
demonstration : Create a Main Main method
public class Demo02Thread {
//3. Set up TRead Subclass object of class ,
public static void main(String[] args) {
MyTread mt=new MyTread();
//4. call Tread Methods in class start Method , Start a new thread , perform run Method
mt.start();
for (int i = 0; i <20 ; i++) {
System.out.println("main:"+i);
}
}
}
Create a MyThread Class inheritance Thread class
package cn.itcast.day01.Demo02;
//1. Create a Tread Subclasses of classes ,
public class MyTread extends Thread{
//2. stay Tread Class Tread Class run Method , Set up thread tasks
@Override
public void run() {
for (int i = 0; i <20 ; i++) {
System.out.println("run:"+i);
}
}
} Execution principle :
边栏推荐
- 苹果不差钱,但做内容“没底气”
- 伯克利、MIT、剑桥、DeepMind等业内大佬线上讲座:迈向安全可靠可控的AI
- C language to realize mine sweeping (simple version)
- Dongyuhui is not enough to bring goods to "rescue" live broadcast
- 主数据建设的背景
- Interpreter mode -- formulas for dating
- Popupwindow touch event transparent transmission scheme
- Responsibility chain mode -- through interview
- The first public available pytorch version alphafold2 is reproduced, and Columbia University is open source openfold, with more than 1000 stars
- [普通物理] 光栅衍射
猜你喜欢

Basic operation of sequence table

Design of routing service for multi Activity Architecture Design

Responsibility chain mode -- through interview

伯克利、MIT、剑桥、DeepMind等业内大佬线上讲座:迈向安全可靠可控的AI

A/B测试助力游戏业务增长

Internet of things? Come and see Arduino on the cloud
![[performance tuning basics] performance tuning strategy](/img/83/be41a6a0c5c186d3fb3a120043c53f.jpg)
[performance tuning basics] performance tuning strategy

微信小程序自定义tabBar

二叉树的基本性质与遍历

字节、腾讯也下场,这门「月赚3000万」的生意有多香?
随机推荐
opds sql组件能不能将流程参数通过上下文传给下一个组件
Sequence stack version 1.0
微信小程序自定义tabBar
苹果不差钱,但做内容“没底气”
I feel that I am bald again when I help my children with their homework. I feel pity for my parents all over the world
得物多活架构设计之路由服务设计
Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading
Coinbase will launch the first encryption derivative for individual investors
Camera rental management system based on qt+mysql
Interpreter mode -- formulas for dating
消息称腾讯正式宣布成立“XR”部门,押注元宇宙;谷歌前 CEO:美国即将输掉芯片竞争,要让台积电、三星建更多工厂...
Leetcode(146)——LRU 缓存
Handling of garbled JMeter response data - three solutions
【建议收藏】时间序列预测应用、paper汇总
主数据建设的背景
Design of routing service for multi Activity Architecture Design
DX12引擎开发课程进度-这个课程到底讲到哪里了
Wechat applet custom tabbar
顺序栈遍历二叉树
How to enhance influence