?????????????????У???????????????????????????λ?????????????????????????????????Android????Linux Kernel???У????????????????????????????θ?????????л?????????????????????????о?nice??Linux???Android???е???á?
?????Щ????
???????? ?????????У????????е???壬?????????????
??????? ????????????е?λ????????????????????С???????????????п????ж?????????
????nice????????
????Linux?У????nice value?????3??nice??????趨??????????????????????????????nice????????????
????nice??????Χ?-20??19??
???????????£?nice???????0??????????????????
????nice???????????????????????CPU????????????nice??С?????????????????????CPU???????????
???????nice??-20?????????????nice??19?????????????
??????????fork???????????nice??????????????????renice???????nice???????????
???????????
????nice???????????????????????????????????????????????????????????????????????????????????????????????????????е???????????????????????????е??????????????е??????????????????????????????????????????????????????????????????????nice????????????????????????????????
????renice
????????????μ???????????????????????????????趨nice???
????nice -n 10 adb logcat
???????????????????????????????renice?????nice?
????sudo renice -n 0 -p 24161
????????????????root????-p???????????id??
???????renice??????Linux???а???-n ????????????????????????Mac??-n??????????????????????? ??????Mac?£???????????nice???19???10??????????????sudo renice -n -9 -p 24161???????????????????????
????Android?е?nice
????????Android????Linux Kernel????Android???????nice?????????????????????????????????£?
????Android????????????Linux???а????????????nice?????????
????renice???root?????????????????
??????????
????????????????????????????????????????????????????е??????????????Android???????????????????????Android API?汾????????? Java ????汾??
????Android API
????Android?е??????????????漲?????£????????????????nice???????????????????????????????????????
????THREAD_PRIORITY_DEFAULT??????????????????0??
????THREAD_PRIORITY_LOWEST?????????????19??
????THREAD_PRIORITY_BACKGROUND ?????????????????????????10??
????THREAD_PRIORITY_FOREGROUND ????????????UI???????????????????????????????????????????????????-2??
????THREAD_PRIORITY_DISPLAY ?????UI???????????????????????THREAD_PRIORITY_FOREGROUND??????????????????????????????????????-4??
????THREAD_PRIORITY_URGENT_DISPLAY ??????????????????????????????????????????????????ó???????????-8??
????THREAD_PRIORITY_AUDIO ??????????????????????????????????????? -16??
????THREAD_PRIORITY_URGENT_AUDIO ???????????????????THREAD_PRIORITY_AUDIO?????????????????????????????-19??
????THREAD_PRIORITY_MORE_FAVORABLE ???THREAD_PRIORITY_DEFAULT??????????-1??
????THREAD_PRIORITY_LESS_FAVORABLE ???THREAD_PRIORITY_DEFAULT???????Щ????1??
???????Android API????????????????????????????????????android.os.Process.setThreadPriority???????ɡ?????????????????????????????Ч??????renice??
????new Thread () {
????@Override
????public void run() {
????super.run();
????android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
????}
????}.start();
????Java???API
????Java?Thread??????????????????
????MAX_PRIORITY??????android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY????10??
????MIN_PRIORITY??????android.os.Process.THREAD_PRIORITY_LOWEST????0??
????NORM_PRIORITY??????android.os.Process.THREAD_PRIORITY_DEFAULT????5??
???????setPriority????????????????????????????getPriority????????????????????
??????Android???У??????????Java?????API?????Android????API??????????????????Android???н????趨??μ????????
???????
????Android API????????????Java???API????????????????????????? android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND) ?????Java???API??Thread.getPriority()?????????????????????
????new Thread() {
????@Override
????public void run() {
????super.run();
????Log.i(LOGTAG?? "Java Thread Priority Before=" + Thread.currentThread().getPriority());
????Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
????Log.i(LOGTAG?? "Java Thread Priority=" + Thread.currentThread().getPriority());
????}
????}.start();
?????????????????????
????I/MainActivity( 3679): Java Thread Priority Before=5  I/MainActivity( 3679): Java Thread Priority=5
???????????????????????????????????ANR trace??????????????ANR???????У?prio=5??proi????????Java???API??????????????nice=-6?е?nice?????Android API?汾????????????
????"main" prio=5 tid=1 NATIVE
????| group="main" sCount=1 dsCount=0 obj=0x41690f18 self=0x4167e650
????| sysTid=1765 nice=-6 sched=0/0 cgrp=apps handle=1074196888
????| state=S schedstat=( 0 0 0 ) utm=5764 stm=3654 core=2
????#00  pc 00022624  /system/lib/libc.so (__futex_syscall3+8)
????#01  pc 0000f054  /system/lib/libc.so (__pthread_cond_timedwait_relative+48)
????#02  pc 0000f0b4  /system/lib/libc.so (__pthread_cond_timedwait+64)
????????ANR
??????????????????Android?е?ANR???????WorkerThread??????IO??????????WorkerThread??????????????????IO???????????????????????????????????workerThread??????THREAD_PRIORITY_BACKGROUND??????????????????????????