6. Java concurrency and multithreading-concurrency and parallelism

Source: Internet
Author: User

The following information is transferred from http://tutorials.jenkov.com/java-concurrency/concurrency-vs-parallelism.html (using Google Translate):

Terminology concurrency and parallelism are commonly used in multithreaded programs. But what exactly does concurrency and parallelism mean, are they the same terminology or what?

The short answer is "no". They are not the same terminology, although they look very similar on the surface. It took me some time to finally find and understand the difference between concurrency and parallelism. Therefore, I decided to add a text about concurrency and parallelism in this Java concurrency Tutorial.

Concurrent

Concurrency means that the application is simultaneously on multiple tasks simultaneously. If the computer has only one CPU, the application may not progress on multiple tasks at the same time, but it will process multiple tasks at once within the application. It does not complete a task completely until the next start.

Parallel

Parallelism means that applications decompose their tasks into smaller subtasks that can be processed in parallel, for example, on multiple CPUs simultaneously.

Concurrency and parallelism details

As you can see, concurrency is about how the application handles multiple tasks it handles. Applications can process a task in time (order) or work on multiple tasks concurrently (concurrency).

On the other hand, and?? How the application handles each individual task. Applications can process tasks from beginning to end, or break down tasks into subtasks that can be done in parallel.

As you can see, the application can be concurrent, but not parallel. This means that it handles multiple tasks at the same time, but the tasks are not broken down into subtasks.

The application can also be parallel, but not concurrent. This means that the application can only work on one task at a time, and that the task is decomposed into a sub-task that can be processed in parallel.

In addition, applications can be both concurrent and not parallel. This means that it can only perform one task at a time, and that the task will not be decomposed into a sub-task that executes in parallel.

Finally, an application can also be concurrent and parallel, because it works on multiple tasks at the same time, and also breaks down each task into sub-task execution in parallel. However, in this case, some of the benefits of concurrency and parallelism may be lost because the CPUs in the computer have kept merging busy, concurrent, or parallelized. Combining it may only result in a small performance gain or even a loss of performance. Be sure to analyze and measure before you blindly adopt parallel parallel models.

6. Java concurrency and multithreading-concurrency and parallelism

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.