当前位置:网站首页>Advanced API (multithreading 02)
Advanced API (multithreading 02)
2022-07-03 07:01:00 【Bugxiu_ fu】
Multithreaded life cycle ( The illustration )
Common methods of multithreading
Case study
public static void main(String[] args) {
The current program has 2 Thread thread main Threads gc Threads
demand : Open up a custom thread
Create a custom thread
Thread_01 t1 = new Thread_01();
t1.start();// Open thread
Multithreaded life cycle
1. New state
When a thread is instantiated MyThread mt = new MyThread();
2. Operational state ( Ready state )
mt.start(); Not run immediately , Just have the qualification to run , Waiting for preemption CPU Resources for .
3. Running state
When multiple threads can run again , One of them is selected , Directly reach the running state
4. Blocked state , Waiting in line , Lock pool status
The thread calls some specific methods to make the thread realize some requirements
Thread.sleep();
5. Death state
run Method ,main,stop( Not recommended )
Multiple threads do the same thing Use Runnable Instead, use Thread
System.out.println(" Custom thread : "+Thread.currentThread().getName());
}
/*
* 1. multitasking / Program / process / Threads / Multithreading
*
* 2. Multithreaded implementation
* (1) Inherit Thread class
*
* (2) Realization Runnable Interface
*
* rewrite run Method , Put all process codes here , To control the operation through threads
/*
Multithreading approach :
setPriority|getPriority--- Set and get the priority of the thread
Thread.sleep(long millis)--- Thread sleep
wait--- Thread waiting
Thread comity yield
yield--- Thread concession ( Let the present seize cpu Thread exited cup Redo the waiting queue )
join--- Thread join ( Add more urgent threads , Make the current thread temporarily blocked )
notify|notifyAll-- Wake up the thread
边栏推荐
- 10000小时定律不会让你成为编程大师,但至少是个好的起点
- JMeter test result output
- UTC时间、GMT时间、CST时间
- Flask Foundation
- [set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*
- Application scenarios of Catalan number
- 机械观和系统观的科学思维方式各有什么特点和作用
- Tool class static method calls @autowired injected service
- 2022-06-23 vgmp OSPF inter domain security policy NAT policy (under update)
- Use of framework
猜你喜欢
![[vscode - vehicle plug-in reports an error] cannot find module 'xxx' or its corresponding type declarations Vetur(2307)](/img/7f/3d6b6ea5319f7165e07baf0a78d318.jpg)
[vscode - vehicle plug-in reports an error] cannot find module 'xxx' or its corresponding type declarations Vetur(2307)

Software testing learning - day 3

10000小時定律不會讓你成為編程大師,但至少是個好的起點

Integration test practice (1) theoretical basis

On the practice of performance optimization and stability guarantee

Inno Setup 制作安装包

Summary of the design and implementation of the weapon system similar to the paladin of vitality

Journal quotidien des questions (11)

New knowledge! The virtual machine network card causes your DNS resolution to slow down

Specified interval inversion in the linked list
随机推荐
centos php7.3安装redis扩展
IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library
Realize PDF to picture conversion with C #
Distributed ID
MySQL mistakenly deleted the root account and failed to log in
[set theory] partition (partition | partition example | partition and equivalence relationship)
How can the server set up multiple interfaces and install IIS? Tiantian gives you the answer!
Shim and Polyfill in [concept collection]
Practice of enterprise ab/testing platform
Hands on redis master-slave replication, sentinel master-slave switching, cluster sharding
DBNet:具有可微分二值化的实时场景文本检测
Sorting out the core ideas of the pyramid principle
MySQL syntax (basic)
crontab定时任务
Ruoyi interface permission verification
(翻译)异步编程:Async/Await在ASP.NET中的介绍
每日刷題記錄 (十一)
HMS core helps baby bus show high-quality children's digital content to global developers
Stream stream
Dbnet: real time scene text detection with differentiable binarization