Java multi-threading of the thread life cycle

A, Java thread scheduling method:

1, with the priority of threads FIFO queue (first come, first served), using the time-slice strategy.
2, high-priority, use preemptive scheduling policy priority.

Two, Java thread priority:

1, the thread priority class
MAX_ the PRIORITY: 10, min_ the PRIORITY: 1, the PRIORITY NORM:. 5
2, a method involving members
getPriority (): returns the thread priority value.
setPriority (int newPriority): change the priority of the thread.
Priority inheriting the parent thread when the thread is created.
Low priority but low probability of obtaining scheduling, not necessarily was only called after the high-priority thread.

Three, Java threads Category:

Java threads in two types: one is a daemon thread , one is user threads .
● in virtually every respect are the same, the only difference is the determination of when to leave the JVM.
● daemon thread is used to service user thread by calling before the start () method.
thread.setDaemon (true) can put a user thread into a daemon thread.
● Java garbage collection is a typical daemon thread.
● If the JVM are daemon threads, the current JVM will exit. (Tusigoupeng, cast aside the bow once the birds are gone )

JDK with Thread.State class defines several state of the thread:
in order to achieve multi-threaded, you must create a new thread object in the main thread. Java language using the Thread class and subclass of an object
to represent the thread in one of its full life cycle usually go through the following five states:
(1) New: When the object is a Thread class or subclass is declared when and create nascent thread object in the new state.
(2) Ready: the thread in the new state is Star (after), will enter the queue of threads waiting for CPU time slice,
at this time it has with the conditions of operation, but not assigned to CPU resources.
(3) run: when the thread is scheduled and ready to get CPU resources, will enter the run state,
RUN () method defines the operations and functions of the thread.
(4) blocking: In certain special cases, to be suspended or artificially perform input and output operation,
so that the CPU and temporarily suspend its own execution, to enter the blocked state.
(5) Death: thread to complete all of its work in advance or thread is forcibly suspended or abnormal lead to the end.

  

 

Guess you like

Origin www.cnblogs.com/ZengBlogs/p/12203363.html