Reprinted please indicate the source
http://blog.csdn.NET/pony_maggie/article/details/43889225
Author: Pony
Java Thread priority ranges from 1 (Thread.MIN_PRIORITY) to 10 (Thread.MAX_PRIORITY). If no settings exist, The default priority for threads is NORM_PRIORITY. This value is 5.
demo creates 10 thread instances that show the current priority of each thread and can modify that priority. The effect of the program is as follows.
As shown in the figure, 10 ticker instances can be up and down to control their priority and can be displayed in real time.
For each ticker, the first box shows a counter indicating how many execution opportunities the current thread has received, and the second box shows the current priority of the thread. Notice that all threads start with a priority of 4, because the thread group has a concept of the highest priority, and all threads in the group can't exceed that priority. You can try clicking the up button, the maximum is to group max priority. This value is 4.
In Java, each thread belongs to a member of a thread group management. For example, if a thread is generated in the main() main workflow of the main function, the generated thread belongs to a member of the main thread group management. Simply put, a ThreadGroup is a class of threads that manages threads. This class is the java.lang.ThreadGroup class.
Thread.MAX_PRIORITY should be the highest priority of thread group in theory, but the actual situation is often more complex. Here are excerpts and translations from JAVAMEX->. Javathreading introduction -> Thread priorioties
For thread priority, we need to pay attention to:
* Thread.setPriority() probably doesn't do anything at all, that's with you. operating system Relevant to Virtual Machine Version
* Thread priority may have different meanings for different thread schedulers, which may not be your intuitive guess. In particular, priority does not necessarily refer to CPU sharing. In UNIX systems, priority can more or less be considered CPU allocation, but not in Windows.
* Thread priority is usually a combination of global and local priority settings. Java's setPriority() method applies only to local priorities. In other words, you can't prioritize the whole range of possibilities. (This is usually a way of protection, and you probably don't want the mouse pointer threads or audio data processing threads to be preempted by other random user threads.)
* Different systems have different ranges of thread priority, but Java defines 10 levels (1-10). This makes it possible for several threads to have different priorities in one operating system, but the same priorities in another (and therefore unexpected behavior)
* Operating systems may (and usually do) add proprietary behavior to threads based on their priority (e.g. "only give a quantum boost if the priority is below X"). Again, there are some differences in the definition of priority between different systems.
* Thread schedulers in most operating systems actually perform temporary operations on thread priorities from a strategic perspective (e.g. when a thread receives an event or I/O it is waiting for), the operating system usually knows the most, and trying to control priorities manually may only interfere with the system.
* Your application usually does not know which threads other processes are running, so the impact of changing the priority of a thread is difficult to predict for the entire system. For example, you may find that you have a low-priority thread that you expect to occasionally run in the background that hardly runs because a virus monitor runs at a slightly higher priority (but still below normal priority) and you can't predict the performance of your program, which will depend on your client. The antivirus program used varies.