1. Description
When the current thread does not specify a priority, all threads have normal priority.
Priority is specified from 1 to 10. 10 shows the highest priority, 1 shows the lowest priority, and 5 shows the normal priority. The thread with the highest priority executes first. However, there is no guarantee that the thread will enter the running state when it is started.
A running thread may always have a higher priority than a thread waiting for a chance to run in the thread pool.
The scheduler decides which thread to execute.
t.setPriority() is used to set the priority of the thread.
Before the thread start method is called, remember the priority of the thread.
MIN_PRIORITY, MAX_PRIORITY, NORM_PRIORITY, etc., set the priority. The priority of the Java thread is an integer.
2. Example
public static final int MIN_PRIORITY = 1; public static final int NORM_PRIORITY = 5; public static final int MAX_PRIORITY = 10;
Collections in Java are mainly divided into four categories:
1. List: ordered and repeatable;
2. Queue: ordered and repeatable;
3. Set: non-repeatable;
4. Map mapping: unordered, unique keys, but not unique values.
The above is the detailed content of Java thread priority instance analysis. For more information, please follow other related articles on the PHP Chinese website!