Java Concurrency and multithreading introduction of "translation"

Source: Internet
Author: User

Jakob Jenkov Translator:simon-sz proofreading: Fang Fei

http://tutorials.jenkov.com/ java-concurrency/index.html

In the past single-CPU era, single-tasking can only execute a single program at a point in time. Later in the multitasking phase, computers can perform multitasking or multiple processes in parallel at the same point in time. Although it is not really the "same point in time", but multiple tasks or processes share a CPU, and the operating system to complete the multi-tasking CPU switching, so that each task has a chance to get a certain time slice run.

With the new challenges that multitasking poses to software developers, the program is not supposed to monopolize all CPU time, all memory, and other computer resources. A good example of a program is to release the resources when they are no longer being used, so that other programs can have access to those resources.

then developed to multithreading technology, so that within a program can have multiple threads in parallel execution. The execution of a thread can be considered a CPU in the execution of the program. When a program runs under multiple threads, it is as if more than one CPU is executing the program at the same time.

Multithreading is more challenging than multitasking. Multithreading is performed in parallel within the same program, so concurrent read and write operations are performed on the same memory space. This may be an issue that you never encounter in a single-threaded program. Some of these errors may not necessarily occur on a single CPU machine, since two threads never get really parallel execution. However, the advent of a more modern computer with multicore CPUs also means that different threads can be executed in parallel by different CPU cores in a true sense.

If a thread reads one memory and another thread is writing to that memory, what will the thread that reads the result get? is the old value before the write operation? Or the new value after the write operation is successful? or half the value of a new scuffed? Or, if two threads write the same memory at the same time, what will happen after the operation is completed? is the value written by the first thread? Or the value that the second thread writes? Or is it a mixed value written by two threads? As a result, any results are possible without proper precautionary measures. And this behavior is not even predictable, so the results are also uncertain.

multithreading and concurrency in Java

Java is one of the first languages to support multithreaded development, and Java learning supports multithreaded capabilities from the outset, so Java developers can often encounter the problem scenarios described above. This is why I want to write this series for Java concurrency technology. As a note to yourself and as a follower of other Java developers, you can benefit.

The series focuses on Java multithreading, but some of the problems that arise in multi-threading are similar to the presence of multitasking and distributed systems, so the series will refer to multi-tasking and distributed systems as a reference, so it is called "concurrency" rather than "multithreading."

original articles, reproduced please specify: reproduced from ifeve.com


Java Concurrency and multithreading introduction of "translation"

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.