Home > Java > javaTutorial > Java thread priority instance analysis

Java thread priority instance analysis

WBOY
Release: 2023-04-19 16:19:06
forward
1430 people have browsed it

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;
Copy after login

What collection classes are there in Java

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template