What is multithreaded multi-process

Source: Internet
Author: User
Tags ticket

1: To understand multi-threading, you must first understand the thread, and to understand the thread, you must first understand the process, because the thread is dependent on the process and exists.

2: What is a process?
Through the Task Manager we see the existence of the process.
By observing, we find that only the running program will appear.
Process: Is the program that is running.
A process is an independent unit of system resource allocation and invocation. Each process has its own memory space and system resources.

3: What is the point of multi-process?
A single-process computer can do only one thing, and we now have computers that do multiple things.
Example: While playing the game (the game process), while listening to music (music process).
This means that computers now support multiple processes and can perform multiple tasks within a single time period.
And, you can increase the CPU utilization.

Problem:
Do you play the game while listening to the music at the same time?
No. Because a single CPU can only do one thing at a certain point in time.
While we are playing the game, or listening to music, the CPU is doing the program between the efficient switching let us feel that it is at the same time.

4: What is a thread?
Multiple tasks can be performed within the same process, and each of these tasks I can see is a thread.
Thread: is the execution unit of the program, the execution path. is the most basic unit of the CPU used by the program.
Single thread: If the program has only one execution path.
Multithreading: If the program has more than one execution path.

5: What is the point of multithreading?
Multithreading exists, not to improve the execution speed of the program. In fact, to improve application usage.
The execution of the program is actually in the grab CPU resources, CPU execution right.
Multiple processes are robbing this resource, and one of those processes has a higher chance of grabbing CPU execution if the execution path is more.
We are not sure which thread will be able to grab at any time, so the execution of the thread is random.

6: Multithreading (understanding)
(1) Multithreading: One application has multiple execution paths
Process: The application being executed
Threads: Execution unit of a process, execution path
Single thread: One application has only one execution path
Multithreading: One application has multiple execution paths

What is the meaning of multi-process?
Improve CPU utilization
What is the meaning of multithreading?
Increase application usage
(2) How does the Java program run and the JVM start-up multithreaded?
The A:java command to start JVM,JVM initiates a process that initiates a main thread.
B:JVM startup is multithreaded because it has a minimum of two threads to boot, the main thread and the garbage collection thread.
(3) Multi-threaded implementation of the program (self-completion Steps and Code Mastery)
A: Inherit the Thread class
B: Implement Runnable interface
(4) Thread scheduling and priority issues
A: Scheduling of threads
A: time-sharing scheduling
B: Preemptive scheduling (Java is using this scheduling method)
B: Get and set thread priority
A: The default is 5
B: Range is 1-10
(5) Thread control (common method)
A: Dormant Threads
B: Join Thread
C: comity Thread
D: Background Thread
E: Terminate thread (Master)
(6) The life cycle of a thread (referencing the thread life cycle plot. bmp)
A: New
B: Ready
C: Run
D: Blocking
E: death
(7) The realization of Ticket sale procedure in cinemas
A: Inherit the Thread class
B: Implement Runnable interface
(8) Problems with the ticket sales process in cinemas
A: In order to better match the real scene, added hibernation 100 milliseconds.
B: Problem of selling tickets
A: multiple times with the same ticket
B: Negative votes
(9) The reason of multithreading security problem (also is the basis for us to determine whether a program is a thread security problem)
A: whether there is a multi-threaded environment
B: Do you have shared data
C: Is there more than one statement to manipulate shared data
(10) Resolve thread safety issues synchronously
A: Synchronizing code blocks
Synchronized (object) {
Code that needs to be synchronized;
}

The lock object here can be any object.

B: Synchronization method
Add synchronization to the method.

The lock object here is this

C: Static Synchronization method
Add synchronization to the method.

The lock object here is the byte-code file object of the current class (reflection-re-bytecode file object)
(11) Review of previous thread-safe classes
A:stringbuffer
B:vector
C:hashtable
D: How to turn a thread-unsafe collection class into a thread-safe collection class
You can use the Collections tool class method.

What is multithreaded multi-process

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.