##### The reason concurrent programming is confusing is that there is more than one solution to a problem that requires concurrency, there is more than one way to implement it, and there is no clear mapping between them.

Problems solved using concurrent programming can be categorized into two categories: “speed” and “designmanageability.”

  1. Speed advantage:
  • Multiprocessor: Concurrency on multiple processors will definitely make your program run faster.
  • Uniprocessor: In the case of a uniprocessor machine, concurrent programming may be the same as sequential programming. However, if one of the tasks is likely to block, there is a great benefit to using concurrent programming, even with a single processor, so that while one task is blocked, other tasks can continue to run.
  • Responsive user interface: On a single processor performance improvement of the most typical example is “event-driven programming”, such as creating a responsive user interface, which has a button, if we do not use the concurrent programming, so we need in our writing every code snippet should have about the detection of user input, if we use the concurrent programming, We just need to restart a thread to listen for user input. Concurrency implementation: The most direct way to achieve concurrency is at the operating system level, using processes. Processes are self-contained programs that use their own address space. The operating system isolates processes from each other, so it is relatively easy to program processes without having to worry about synchronization of shared resources. But in Java concurrent programming, because threads share the same memory or IO resources, so Java multithreaded programming needs to consider the synchronization of shared resources. Choice between process and Java thread: Processes are indeed a way to achieve concurrency, butunfortunately there are generally quantity and overhead limitations toprocesses that prevent their applicability across the concurrency spectrum.
  1. Design advantages:
  • In general, threads allow you to create more loosely coupled designs.
  • Single processor: While concurrent programming on a single processor can still only do one thing at a time, it brings an important organizational advantage: your design is greatly simplified. Like simulation.
  • Simulation example: Without concurrency, simulation becomes very difficult. Simulations typically involve multiple interacting elements, each with its own “mind”, and although each element is driven by the same processor from the programmer’s point of view, by design, each element pretends to have its own processor and run its own task.

##### 2. Risks

  1. Security issues

The main problem is that multiple threads sharing data can produce results that do not match expectations

  1. LiVENESS

Activity problems occur when an operation cannot continue. Such as deadlocks, hunger, live locks and so on. (Deadlock, hunger, live lock can be their own baidu)

  1. Performance issues

A. If there are too many threads, the CPU switches frequently, and too much time is spent on scheduling.

B. Multithreaded environments must use synchronization, which inhibits many of the optimizations the compiler wants to make.

C. Too many threads consume too much memory.