Operating system processes and threads knowledge summary

Previous: Java in the ">>" and ">>>" What is the difference?

1, the stack of data:
stack frame: a description of the method of execution moment - a method to begin generating war frame, the method has finished executing, the destruction of the stack frame.
There stack frame shape local variables / parameters Method

2, the main purpose of the computer: running a variety of programs, the program is run up through this process of abstraction process.

3, OS (operating system) is a management software that manages two categories: tangible and intangible hardware activities.
Operating system called management units that manage the distribution of rights, resources, resource allocation is the process out.
Divided into: process management, memory management, file management, network management, driver management.

4, the code only to the CPU in order to run. So CPU resource is the most valuable.

5, process management / process scheduling: OS by constantly switching process, CPU resources to manage the process.

6, several switches may be time to process:
i) are high-priority process preempt
ii) execution ended
iii) waiting for an external event IO
iv) give up
v) time slice is exhausted (run simultaneously achieve a hypothetical)

7, the process of switching (operating system executing code completion):
the I) will have the protection of the current process context
context under II) will have a process of recovery.

8, the process is the smallest unit of the operating system resource allocation.
A thread is the smallest unit of scheduling the operating system (OS CPU resource allocation smallest unit) in order to describe the Thread object.

9, attribute information of the initialization of the object:
the I) PID
II) program information
III) Statistics
IV) scheduling information

10, if a program to be executed, the thread must grab the CPU resources.

11, multi-threaded apply what scene? What advantage is that?
1) may improve the speed of execution (more than a scheduling unit, have the opportunity to grab more than one CPU).
2) Under certain scenarios, it is necessary to deal with multi-threading, for example, when there is obstruction IO (a scheduling unit fell, the rest of the unit can grab CPU scheduling work).

Objective 12, override the run method, but should guide the work of the thread, and no other action.
Start does not need to override, and start method is called, will thread into the ready queue with scheduling opportunities (opportunity to grab the CPU).

13, thread common attributes: ID, name, status, priority, whether the background thread is alive, would have been interrupted.

14, Therad of common operations:
the I) starting a thread - the thread into the ready queue, have qualified to compete for the CPU --start;
Ii) notify a thread to stop (interrupt thread) - recommendation is not mandatory --interrupt ;
Iii) waits for a thread to stop --join;
Iiii) (obsolete method) can be forced to stop to let the thread approach, but is not recommended for use.

15, how to feel notice?
I) If you are operating call sleep like to interruptedException unusual situation is notified
II) If not, you need to use Thread. Interrupted (more recommended) or t.isInterrupted
Iii) the Thread. Interrupted call resets the interrupt flag ( That light dimmed)
after interruptedException exception is thrown resets the interrupt flag
Cause: hope this notification to this end, will not affect the follow-up.

16,
. 1) Thread.currentThread () returns a reference to the current thread - which code execution thread, which thread is the current code;
. 2) the Thread Interrupted The () to stop the notification;
. 3) the Thread.sleep (ms) Sleep x milliseconds - to abandon the current thread CPU, the state modification (not in competition for CPU), to set up their own alarm clocks, after x milliseconds, re-enter the ranks to snatch the CPU;
at Sleep time is certainly> = x milliseconds, may be greater than x milliseconds ;
TimeUnit.SECONDS.sleep (s);
TimeUnit.HOUR.sleep (s);
4) Thread.yield (); give up the CPU, but the CPU contention to retain eligibility. Running from ready to
not TERMIANATED NEW and return true; 5) isAlive ().

17, the effect of thread state: when reference JVM internal thread scheduling; DEBUG thread --jconsole programmer observation tool.

18, the thread status and meaning what?
New: thread object has just been created, there is no rush qualifications of the CPU
RUNNING has two meanings: ready (in the ready queue - are eligible to grab the CPU), running (grab CPU, and has been running on a cpu)
BLOCKED, TIMED_WAITING, WAITING indicates that the threads are not eligible to grab CPU. Thread alive only temporary abdication grab CPU.

19, the transfer between threads: BLOCKED, TIMED_WAITING, WAITING come back all the time to return to ready, go grab CPU

20, thread-safe concept: operating results multithreaded program can guarantee 100% accuracy, can be said to be thread-safe, or even 99% of the cases, the result is correct, is not thread safe.

21, because there is a thread of random factors in the implementation process:
the I) when uncertainty from the CPU switch
Ii) who was chosen to switch on the CPU uncertainty
which led to the results of the program is uncertain, that is not according to our expectations, we call: thread safe.
On the contrary: the so-called security thread is to write the code to ensure correct results expected return of 100%.

22 two necessary conditions, not all multi-threaded program will appear this phenomenon, there are two random phenomena:
the I) variables (resources) operations between multiple threads are shared
Ii) to be shared among multiple threads variables (resource) is modified operation.
As long as the absence of one of the above conditions, then the multithreaded code is thread-safe (no bug)
have in many cases is inherently thread-safe.

23, the memory area is divided in Java: Program Counter (PC), stack (native method stacks, JVM virtual machine stack), the heap, the method area, the constant pool.

24, the stack effect: that the dynamic process of the operating method - is mainly stored in the stack frame.

25, Java parameter passing only the value transfer (copy process value) - the change does not affect the parameter argument (either basic data types or reference data type).

26, which is shared memory area, which area is private?
Program Counter (PC): private to each thread; each thread needs to run his own record gone (nextPCValue).
Stack (whether native method stacks or stack JVM) for each thread private; each thread in the current execution path method is likely to be different.
More than two is a dynamic process:
The following three data storage:
heap, the method area, the constant pool: All threads share the same copy.

27, there are two types of variables: one is the basic data types, one is a reference data type. Variable types can not decide whether this is a form of variable shared among threads of variables: decision variables are the form factors shared between the stowed position and whether the threads.
Parameter, local variables - stored in the stack frame - they are proprietary between threads;
Properties - stored in the object - the object (not including the reflecting object) is stored in the stack - attribute between threads share ; a
static properties - in classes - the class in the process zone - static property is shared between threads.


Here Insert Picture Description

Published 46 original articles · won praise 82 · views 8140

Guess you like

Origin blog.csdn.net/weixin_45662626/article/details/104985110