1220 Lessons Learned

Thread: Process to perform during operation, the clues
single-threaded: May have had a single clue, the problems
relative efficiency under

Process
definition, the data structure and a process which can be performed in the last operation which
he has two basic characteristics:
1. The processes are independent units are available resources
2. while the process is a basic unit may be independently dispatched and scheduled these two basic implementation so that it can run independently, can also be run concurrently. But running concurrently, the system also need to perform a series of operations:
1. The need to create a process, and to whom they must allocate resources
2. The revocation process, resource recycling
3. The process of switching

Thread
in a process can contain one or more threads, a thread is a thread of execution inside the program.

Thread
the Java thread controlled by the Thread class, a class of Thread object represents a thread, and can only represent a thread
through the object and it defines the Thread class, we can get the current thread object, get the name of a thread, it is possible to achieve control thread suspended for some time and so on.
Each thread is run by the process of a specific object corresponds Thread () to complete its operation, the method run () is an operating member
used Start () method, the thread enters Runable () runnable thread to it the scheduler register this thread
calls Start () method does not necessarily execute the thread immediately

In a single thread, main method must continue to run after run method returns, if a class inherits the Thread, you must override the run () method
Life Cycle
New (new)
Ready (runnable)
running (running)
blocking (bolcked)
death (dead)

Thread class inheritance, can not inherit from other classes, the advantage is to simply write, you can directly manipulate thread

And thread control methods related to
start () the new process into the runnable state
run () thread into the running state of
wait () thread into the wait state
sleep () thread to sleep for a specified period of time
join () forced to join a thread
interrupt interrupt thread
notity () / notilyAll () wake up other threads

Thread blocking and unblocking
when one thread is running a piece of code, this time also need to run another thread at a time, but before that thread execution during operation is completed, another thread can not get into the CPU execution right (call sleep by going to sleep apnea state, but the CPU did not execute the right to pay out, and call the wait method sucked CPU implementation of the right to another thread), this time it will cause thread blocks.

Call sleep to give up possession of resources
call blocking IO method
waiting for synchronization lock
waiting notification
calls Suspend Suspend thread

Guess you like

Origin blog.51cto.com/14589602/2460658