当前位置:网站首页>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
边栏推荐
- JMeter test result output
- 机器学习 | 简单但是能提升模型效果的特征标准化方法(RobustScaler、MinMaxScaler、StandardScaler 比较和解析)
- (翻译)异步编程:Async/Await在ASP.NET中的介绍
- Software testing learning - day one
- Golang operation redis: write and read kV data
- Modify MySQL password
- How to migrate or replicate VMware virtual machine systems
- Redis command
- C2338 Cannot format an argument. To make type T formattable provide a formatter<T> specialization:
- Practical plug-ins in idea
猜你喜欢
Summary of remote connection of MySQL
Practical plug-ins in idea
The 10000 hour rule won't make you a master programmer, but at least it's a good starting point
IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library
[Fiddler problem] solve the problem about Fiddler's packet capturing. After the mobile network is configured with an agent, it cannot access the Internet
Sorting out the core ideas of the pyramid principle
How to migrate or replicate VMware virtual machine systems
Integration test practice (1) theoretical basis
La loi des 10 000 heures ne fait pas de vous un maître de programmation, mais au moins un bon point de départ
卡特兰数(Catalan)的应用场景
随机推荐
Dbnet: real time scene text detection with differentiable binarization
Unittest attempt
每日刷题记录 (十一)
Selenium key knowledge explanation
Understand software testing
[Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones
Laravel框架 踩坑(一)
DNS forward query:
Advanced API (serialization & deserialization)
[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*
Notes on the core knowledge of Domain Driven Design DDD
In depth analysis of reentrantlock fair lock and unfair lock source code implementation
Software testing assignment - day 3
Sorting out the core ideas of the pyramid principle
golang操作redis:写入、读取hash类型数据
UTC time, GMT time, CST time
How does the insurance company check hypertension?
10 000 volumes - Guide de l'investisseur en valeur [l'éducation d'un investisseur en valeur]
保险公司怎么查高血压?
JS date comparison