Java Concurrency Learning Note i

Source: Internet
Author: User

1, concurrency can improve the speed of the program, to better manage the program design.

2, on the multiprocessor host, you can run multiple tasks on these processors, improve throughput, however, on a single processor host, using concurrency, it seems to be more expensive than the synchronous execution of the program resources, because it increases the cost of the so-called context switch, to switch from one task to another, here, We may think that the use of concurrency on the processor's host does not improve the performance of the program, but instead consumes more resources, but there is a problem that makes concurrency different on a single processor, which is blocking. Let's take a look at the meaning of blocking, and if a task in the program is unable to continue execution because of a condition outside the control range (typically IO), then we say the task is blocked. This time if there is no concurrency, the entire program will stop, until the external conditions are satisfied, conversely if the use of concurrency, then when the task is blocked, other tasks in the program can continue to execute, so that the entire program can continue to go forward. In summary, from a performance point of view, if there is no task blocking, concurrency on a single processor is not mission-meaningful.

3, concurrency on a single processor common use is event-driven programming

4, concurrency in the embodiment of Java, is implemented by the thread. We know that concurrent programs divide programs into separate, separate, running tasks. By using the multithreading mechanism, one of these separate tasks is driven by a wired thread. A thread is a single sequential control flow in a process, so a single process can have multiple concurrently executed tasks, but your program makes each task seem to have its own CPU, in fact, the underlying mechanism is to slice the CPU time. Java's threading mechanism allows us to detach from the system processor level in concurrent concurrent programming, without caring whether the program is running on a single processor or on multiple processors. The threading mechanism of Java enables our concurrent programming to be based on transparent, extensible methods.


Java Concurrency Learning Note i

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.