当前位置:网站首页>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
边栏推荐
- (翻译)异步编程:Async/Await在ASP.NET中的介绍
- MySQL syntax (basic)
- Pytest attempts to execute the test case without skipping, but the case shows that it is all skipped
- Realize PDF to picture conversion with C #
- JUC forkjoinpool branch merge framework - work theft
- Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
- 服务器如何设置多界面和装IIS呢?甜甜给你解答!
- golang操作redis:写入、读取kv数据
- php artisan
- 多个全局异常处理类,怎么规定执行顺序
猜你喜欢

(翻译)异步编程:Async/Await在ASP.NET中的介绍

Arctic code vault contributor

Sorting out the core ideas of the pyramid principle

多个全局异常处理类,怎么规定执行顺序

2022 - 06 - 23 vgmp - OSPF - Inter - Domain Security Policy - nat Policy (Update)

Dbnet: real time scene text detection with differentiable binarization

Practical plug-ins in idea

How to specify the execution order for multiple global exception handling classes

Interfaces and related concepts

Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
随机推荐
Troubleshooting of high CPU load but low CPU usage
MySQL installation
2022 East China Normal University postgraduate entrance examination machine test questions - detailed solution
JMeter test result output
2022 - 06 - 23 vgmp - OSPF - Inter - Domain Security Policy - nat Policy (Update)
Basic components and intermediate components
The dynamic analysis and calculation of expressions are really delicious for flee
Advanced API (byte stream & buffer stream)
Split small interface
Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record
How to specify the execution order for multiple global exception handling classes
Interface learning
vmware虚拟机C盘扩容
Use the jvisualvm tool ----- tocmat to start JMX monitoring
JMeter JSON extractor extracts two parameters at the same time
Distributed transactions
这两种驱蚊成份对宝宝有害,有宝宝的家庭,选购驱蚊产品要注意
[classes and objects] explain classes and objects in simple terms
Shim and Polyfill in [concept collection]
Winter vacation work of software engineering practice