当前位置:网站首页>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
边栏推荐
- [Fiddler actual operation] how to use Fiddler to capture packets on Apple Mobile Phones
- JMeter JSON extractor extracts two parameters at the same time
- MySQL installation
- Class and object summary
- Summary of remote connection of MySQL
- UTC time, GMT time, CST time
- Operation principle of lua on C: Foundation
- How to migrate or replicate VMware virtual machine systems
- PHP install the spool extension
- The education of a value investor
猜你喜欢

Golang operation redis: write and read kV data
![[untitled]](/img/72/4ff9354634342580a135debb58b60e.jpg)
[untitled]

Daily question brushing record (11)

Reading notes of "learn to ask questions"
![[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*](/img/1f/f579110a408c5b5a094733be57ed90.jpg)
[set theory] equivalence classes (concept of equivalence classes | examples of equivalence classes | properties of equivalence classes | quotient sets | examples of quotient sets)*

VMware virtual machine C disk expansion

IC_ EDA_ All virtual machine (rich Edition): questasim, vivado, VCs, Verdi, DC, Pt, spyglass, icc2, synthesize, innovative, ic617, mmsim, process library

Pits encountered in the use of El checkbox group

Jmeter+influxdb+grafana of performance tools to create visual real-time monitoring of pressure measurement -- problem record

Practical plug-ins in idea
随机推荐
Simple understanding of bubble sorting
Advanced API (byte stream & buffer stream)
UTC time, GMT time, CST time
Liang Ning: 30 lectures on brain map notes for growth thinking
Software testing learning - the next day
Software testing assignment - the next day
PHP install the spool extension
The dynamic analysis and calculation of expressions are really delicious for flee
The 10000 hour rule won't make you a master programmer, but at least it's a good starting point
Software testing learning - day 3
Use of framework
[attribute comparison] defer and async
Notes on the core knowledge of Domain Driven Design DDD
[classes and objects] explain classes and objects in simple terms
每日刷题记录 (十一)
Distributed ID
Personally design a highly concurrent seckill system
[Code] occasionally take values, judge blanks, look up tables, verify, etc
Selenium key knowledge explanation
Climb movie paradise 2021 hot