Android thread priority setting method and tips: android thread priority
The thread priority setting on the Android platform can handle the congestion of many concurrent threads,
For example, many irrelevant threads occupy a lot of CPU time. Although the MultiThread is used to solve slow I/O, reasonable priority allocation is very important for concurrent programming.
Android mainly uses the Java Thread class in terms of threads. we can add the following to the first sentence of the run method in the Thread or Runnable interface:
Process. setThreadPriority (Process. THREAD_PRIORITY_BACKGROUND); // set the thread priority to the background
In this way, when multiple threads are concurrent, the CPU time allocated by many irrelevant threads will be reduced, which is conducive to the processing of the main thread.
Related Thread priorities: Android123 lists the specific definitions of the Android platform in the following categories:
Int THREAD_PRIORITY_AUDIO // priority of the thread used for playing standard music
Int THREAD_PRIORITY_BACKGROUND // standard background program
Int THREAD_PRIORITY_DEFAULT // Default Application priority
Int THREAD_PRIORITY_DISPLAY // standard display system priority, mainly to improve UI refresh
Int THREAD_PRIORITY_FOREGROUND // standard foreground thread priority
Int THREAD_PRIORITY_LESS_FAVORABLE // lower than favorable
Int THREAD_PRIORITY_LOWEST // the lowest priority of valid threads
Int THREAD_PRIORITY_MORE_FAVORABLE // higher than favorable
Int THREAD_PRIORITY_URGENT_AUDIO // The standard audio playback priority.
Int THREAD_PRIORITY_URGENT_DISPLAY // The Standard Display priority, which is also applicable to input events.