Próbuję zmienić priorytet głównego wątku przy użyciu android.os.Process.setThreadPriority()
. Mam przed i po priorytetowej zmiany komunikaty dziennika, oto kod:Zmiana priorytetu wątku nie ma wpływu
public class TestActivity extends Activity {
public final String TAG="TestActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
int tid=(int)Thread.currentThread().getId();
Log.d(TAG,"priority before change = " + android.os.Process.getThreadPriority(tid));
Log.d(TAG,"priority before change = "+Thread.currentThread().getPriority());
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_DISPLAY);
Log.d(TAG,"priority after change = " + android.os.Process.getThreadPriority(tid));
Log.d(TAG,"priority after change = " + Thread.currentThread().getPriority());
}
}
I pojawia się następujący komunikat:
priority before change (getThreadPriority) = 0
priority before change (currentThread().getPriority) = 5
priority after change (getThreadPriority) = 0
priority after change (currentThread().getPriority) = 5
Oznacza to, że priorytetem nie zmieni, niezależnie od metody używam do oceny to. android.os.Process.THREAD_PRIORITY_DISPLAY = -4
, więc po zmianie mojego ouput powinien równać się -4, dlaczego pozostaje taki sam? Dlaczego android.os.Process.setThreadPriority()
nie ma wpływu?
P.S. Czytałem Google Docs na temat wątków, ale nie natrafiłem na żadne problemy wyjaśniające różnicę między android.os.Process.getThreadPriority()
i Thread.currentThread().getPriority()
. Dlaczego te metody zwracają różne wartości?
P.P.S. Thread.currentThread().setPriority()
działa dobrze.