Home >Java >javaTutorial >What is concurrency in java?

What is concurrency in java?

青灯夜游
青灯夜游Original
2019-11-18 17:27:035669browse

What is concurrency in java?

#What is concurrency in java?

Concurrency: refers to the alternate execution of multiple tasks within a certain period of time. When multiple threads are operating, the CPU running time is divided into several time periods, and then the time periods are allocated to each thread for execution. While one thread's code is running, other threads are suspended.

To put it simply, the CPU performs multiple tasks at the same time.

Java concurrency is implemented by multi-threading. [Recommended learning: java course]

In the world of jvm, threads are like unrelated parallel spaces, serialized in the virtual machine. (Of course, this is a more general statement. Threads can interact with each other, and they are not necessarily serial.)

The existence of multi-threading is to squeeze the CPU, improve program performance, and reduce certain design requirements. Complexity (designing programs with realistic time thinking).

Why use multi-threading?

First of all:

From the bottom of the computer: Threads can be compared to lightweight processes, which are the smallest unit of program execution, switching and scheduling between threads The cost is much less than the process. In addition, the multi-core CPU era means that multiple threads can run simultaneously, which reduces the overhead of thread context switching.

From the perspective of contemporary Internet development trends: Current systems often require millions or even tens of millions of concurrency, and multi-threaded concurrent programming is the basis for the development of high-concurrency systems. The use of multi-threading mechanisms can greatly Improve system concurrency and performance.

Go deeper into the bottom layer of the computer:

Single-core era: In the single-core era, multi-threading is mainly to improve the comprehensive utilization of CPU and IO devices.

Multi-core era: The multi-core era is mainly to improve CPU utilization.

What problems may arise from using multi-threading?

The purpose of concurrent programming is to improve the execution efficiency of the program and increase the running speed of the program. However, concurrent programming does not always improve the running speed of the program, and concurrent programming may encounter many problems. For example: memory leaks, context switching, deadlocks, etc., as well as issues limited by hardware and software and idle resources.

The above is the detailed content of What is concurrency in java?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is a proxy in java?Next article:What is a proxy in java?