I have the following code onCreate()
Log.d(TAG, "Setting priority background");
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
Log.d(TAG, Thread.currentThread().getId() + ": " + Thread.currentThread().getPriority());
Log.d(TAG, Process.getThreadPriority(Process.myTid()) + " - myTid() " + Process.myTid() + " Thread.getId() = " + Thread.currentThread().getId());
// start a thread here
Thread thread = new Thread(() -> {
Log.d(TAG, " In new thread");
Log.d(TAG, Thread.currentThread().getId() + ": " + Thread.currentThread().getPriority());
Log.d(TAG, Process.getThreadPriority(Process.myTid()) + " - myTid() " + Process.myTid() + "Thread.getId() = " + Thread.currentThread().getId());
}
The output is:
Setting priority background
1: 5
10 - myTid() 8798 Thread.getId() = 1
In new thread
7534: 10
-8 - myTid() 8819 Thread.getId() = 7534
Can someone please explain:
1) Even though I set setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
the log in the next line shows priority 5
. Why?
2) Where is the -8
coming from in the output for the priority of the second thread?
3) Where is the 10
for the new thread coming from too?
Update:
If I remove the line Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
the output remains the same