Concept part:
1. Concurrency and Parallelism differences:
Concurrency (Concurrency): One processor "simultaneously" handles multiple tasks
Parallel (Parallelism): multiple processors "simultaneously" Handle multiple tasks
2. Advantages and disadvantages of multithreading:
Advantages of Multithreading:
Tasks can be processed in parallel, reducing the wait time for individual tasks
A thread is less expensive than a process or sub-process system
Easier sharing of resources between threads
Leverage CPU resources in multi-core scenarios
Disadvantages of Multithreading: Access violation lock contention – Deadlock – lock granularity context switch overhead synchronization/memory copy Overhead
JVM section:
"Tinking in Java" section:
1. Concurrency has demonstrable certainty, but is actually nondeterministic.
2. If no tasks are blocked, it makes no sense to use concurrency on a single-processor machine.
3. Some programming languages are designed to isolate concurrent tasks from each other, which are often referred to as functional language--erlang.
4. Syntax sugar: while (countdown-->0), private final int id = taskcount++; The use of the rear + + and--, the counter can be added and reduced operation, convenient and clear.
5. Various actuators (Executor):
Cachedthreadpool: Generally preferred, will be created on the same number of threads as required.
Fixedthreadpool: A good thread in advance, limiting the number of threads.
Singlethreadexecutor is like a fixedthreadpool with a number of threads of 1 (it provides long-term survival and concurrency assurance, which is suitable for certain tasks). Singlethreadexecutor serializes all the tasks submitted to it.
6. If you want the task to return a value when it is completed, replace the Runnable interface with callable.
7.
Java Multithreaded Learning Notes