1. System threads visible in Ddms (Andorid3.1 Galaxy Tab 10.1 for example):
Main
Heapworker performing finalize functions and referencing object cleanup
GC Garbage collector garbage Collection
Signal Catcher captures Linux signals for processing
JDWP Java Debug Wire Protocol Debug Protocol Service
Compiler JIT Compiler Instant Compiler
Binder Thread #1 Binder Communication
Binder Thread #2
2. Thread
The thread object, which is an instance of the Java-Defined tread class. is the execution unit with the call stack itself
Typical error: Call run () instead of start () This will cause the run () method of the thread/or Runnable object to be invoked in the current thread. No new threads generated
3. How to change thread priority
(1) Thread priority from 1 to 10
Thread.setpriority () can
New Thread ("thread name") {@override publicvoid Runnable () {} }thread.setpriority (thread.max_priority); // highest priority (occurrence than UI line) Thread.Start ();
Min_priority (1)
Norm_priority (5)--default priority, if no priority is specified, default priority is used
Max_priority (10)
Ilegalargumentexception exception is thrown if the thread priority of the app setting exceeds the range of values (1-10)
(2) Another way is to use the process.setthreadpriority () in the Android.os bag
It is based on the priority of Linux, from 20 (highest) to 19 (lowest)
8 priority levels are defined:
Thread_priority_audio (-16)
Thread_priority_background (10)
Thread_priority_default (0)
Thread_priority_display (-4)
Thread_priority_foreground (-2)
Thread_priority_lowest (19)
Thread_priority_urgent_audio (-19)
Thread_priority_urgent_ DISPLAY (-8)
You can also use Process.thread_priority_less_favorable (+1) and process.thread_priority_less_favorable (-1)
If you want to set the thread priority higher than the default. Then you can use (Thread_priority_default + thread_priority_less_favorable)
In this way, instead of you direct + 1,-1, is because +1 sometimes means to increase the priority, sometimes it is to lower the priority level.
Note: Do not mix thread.setpriority and process.setthreadpriority. Because thread and Linux have different priority definitions.
Note: Changing the thread priority must be very careful. Increasing the priority may speed up the character execution of this thread, but it can negatively affect other threads and affect the overall experience.
The priority aging algorithm can be considered.
Again: The background thread updates the user interface and must be fed back to the main thread, and the view method can only be called in the UI thread.
"Android Application Performance Optimization" chapter 5th Multithreading and synchronization