当前位置:网站首页>What is JUC in high concurrency programming
What is JUC in high concurrency programming
2022-06-12 15:41:00 【It mapper】
JUC What is high concurrency programming JUC
JUC brief introduction
- stay Java in , The thread part is a focus , JUC It's also about threads .JUC Namely java.util .concurrent It's short for toolkit . This is a toolkit for processing threads ,JDK 1.5 The beginning of
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-Cm9nizU6-1646008008803)(C:\Users\admin\AppData\Roaming\Typora\typora-user-images\1646007408924.png)]](/img/fd/eb28d24fdab4a640354196653d87b2.jpg)
Processes and threads
process (Process) A program in a computer is about a running activity on a data set , Is the system resource allocation and scheduling of the basic unit , Is the foundation of the operating system architecture . In modern thread oriented computer architecture , A process is a container for threads . A program is an instruction 、 Of data and its organization describe , A process is an entity of a program . A program in a computer is about a running activity on a data set , Is the system resource allocation and scheduling of the basic unit , Is the foundation of the operating system architecture . A program is an instruction 、 Description of data and its organization , A process is an entity of a program
Threads (thread) It is the smallest unit that the operating system can schedule operations . It is included in the process , Is the actual operation unit in the process . A thread refers to a single sequential control flow in a process , Multiple threads can be concurrent in one process , Each thread performs different tasks in parallel
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-9swGhnUU-1646008008805)(C:\Users\admin\AppData\Roaming\Typora\typora-user-images\1646007482119.png)]](/img/a8/933aeb89c2a4c7582b32052af9591e.jpg)
process : An application running in a system ; Once the program runs, it's a process ; process —— The smallest unit of resource allocation
Threads : The basic unit of time resources allocated to the processor by the system , Or a unit execution flow executed independently within a process . Threads —— The smallest unit of program execution
State of thread
public enum State { /** * Thread state for a thread which has not yet started. */ NEW,( newly build ) /** * Thread state for a runnable thread. A thread in the runnable * state is executing in the Java virtual machine but it may * be waiting for other resources from the operating system * such as processor. */ RUNNABLE,( Be ready ) /** * Thread state for a thread blocked waiting for a monitor lock. * A thread in the blocked state is waiting for a monitor lock * to enter a synchronized block/method or * reenter a synchronized block/method after calling * {@link Object#wait() Object.wait}. */ BLOCKED,( Blocking ) /** * Thread state for a waiting thread. * A thread is in the waiting state due to calling one of the * following methods: * <ul> * <li>{@link Object#wait() Object.wait} with no timeout</li> * <li>{@link #join() Thread.join} with no timeout</li> * <li>{@link LockSupport#park() LockSupport.park}</li> * </ul> ** <p>A thread in the waiting state is waiting for another thread to * perform a particular action. * * For example, a thread that has called <tt>Object.wait()</tt> * on an object is waiting for another thread to call * <tt>Object.notify()</tt> or <tt>Object.notifyAll()</tt> on * that object. A thread that has called <tt>Thread.join()</tt> * is waiting for a specified thread to terminate. */ WAITING,( Be there or be square ) /** * Thread state for a waiting thread with a specified waiting time. * A thread is in the timed waiting state due to calling one of * the following methods with a specified positive waiting time: * <ul> * <li>{@link #sleep Thread.sleep}</li> * <li>{@link Object#wait(long) Object.wait} with timeout</li> * <li>{@link #join(long) Thread.join} with timeout</li> * <li>{@link LockSupport#parkNanos LockSupport.parkNanos}</li> * <li>{@link LockSupport#parkUntil LockSupport.parkUntil}</li> * </ul> */ TIMED_WAITING,( Out of date ) /** * Thread state for a terminated thread. * The thread has completed execution. */ TERMINATED;( End ) }
Concurrency and parallelism
Serial mode
- Serial means that all tasks are carried out one by one in order . Serial means you have to load a load of firewood before you can deliver it , Only delivery to , To get rid of the firewood , And only completed the whole three steps , To move on to the next step , Serial is only one task at a time , And perform the task
Parallel mode
- Parallel means that you can get multiple tasks at the same time , And at the same time to carry out these tasks . Parallel mode is equivalent to a long queue , Divided into short queues , So parallelism shortens the length of the task queue . The efficiency of parallelism is strongly dependent on multiprocesses at the code level / Multithreaded code , From the hardware point of view, it depends on multi-core CPU
Concurrent
- Concurrent (concurrent) It refers to the phenomenon that multiple programs can run at the same time , More detailed is that multiple processes can run at the same time or multiple instructions can run at the same time . But that's not the point , When describing concurrency, we will not deduct the accuracy of such words , The point of concurrency is that it's a phenomenon , Concurrent description Is the phenomenon of multiple processes running at the same time . But actually , For a single core CPU Come on , At the same time Only one thread can run . therefore , there " Running at the same time " It doesn't mean that there are multiple at the same time Thread running phenomenon , This is the concept of parallelism , Instead, it provides a function for users to see multiple programs running at the same time , But in fact, the process of these programs is not always occupied CPU Of , It's a little execution, a little pause
- To solve the problem of large concurrency , It is usually to break down a large task into several small tasks , Because the process scheduling of the operating system is random , So after splitting into several small tasks , May be performed from any small task . There may be some phenomena
- A small task may have been executed more than once , I haven't started the next task yet . At this time, queues or similar data structures will be used to store the results of various small tasks
- There may be the possibility of performing the second step before the first step is ready . At this time , It's usually multiplex or asynchronous , For example, only when you are ready to generate an event notification can you perform a task
- Can be multi process / Multithreading to perform these small tasks in parallel . Or single process / A single thread performs these small tasks , At this time, it is likely to cooperate with multiplexing to achieve high efficiency
Tube side
- Tube side (monitor) Is to ensure that only one process is active in the process at the same time , That is, the operation defined in the process is called by only one process at the same time ( Implemented by compiler ). However, this does not guarantee that the process will execute in the designed order JVM Synchronization is based on entering and exiting the tube (monitor) Object implemented , Each object has a tube side (monitor) object , Tube side (monitor) Will follow java Objects are created and destroyed together The execution thread must first hold the pipe object , Then we can execute the method , When the method is completed, the tube side will be released , The method will hold the pipeline when executing , Other threads can no longer get the same process
User threads and daemons
User threads : Ordinary threads used at ordinary times , Custom thread
The guardian thread : Running in the background , Is a special thread , For example, garbage collection
When the main thread ends , The user thread is still running ,JVM Survive
If there is no user thread , It's all daemon threads ,JVM end
边栏推荐
- Use of packet capturing tool Fiddler: simulating speed limit test process in weak network environment
- Broadcast and multicast (tcp/ip details volume 1/2)
- Preparation of service for robot moving forward and rotating
- Unity get local video / download network video
- Classic case of solidity - Smart games
- Notes on ARM 64 instructions
- Rust小技巧 - 通过FFI编程运行tensorrt模型
- MySQL开发注意事项(阿里巴巴开发手册)
- Using the CSDN markdown editor
- 分布式并发重复提交问题
猜你喜欢
随机推荐
Solutions to some problems of scuacm22 retreat competition before summer training
Understanding of dart typedef
Daily leetcode - 3 Longest substring without duplicate characters
First set and follow set in vernacular
Classification of annotations
Acwing暑期每日一题(6月10日性感素数)
远程操控其它电脑--详细教程
解决log4j2漏洞遭到挖矿、僵尸进程病毒攻击
应势而变,2022年下半场的升级之路
Particle filter learning record
Rust tip - running the tensorrt model through FFI programming
VIM installation and common commands
Learning is an inhumane thing (becoming an expert's internal mind skill)
Understanding of Odom coordinate system
Error 1105: message:\“raft entry is too large
Jupyter notebook new environment shortcut
Fiddler packet capturing (mobile app)
【光源实用案例】 UV-LED固化创新,让产线变得更丝滑
Using the CSDN markdown editor
[jvm learning] local method stack and heap
![[jvm learning] virtual machine stack](/img/64/4942c572f1ae4e4c6e2a6b657660e3.jpg)





![[jvm learning] class loading subsystem](/img/60/e863495ce4ea5826d1404a73c90033.jpg)


