我有以下代码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());
}
输出是:
Setting priority background
1: 5
10 - myTid() 8798 Thread.getId() = 1
In new thread
7534: 10
-8 - myTid() 8819 Thread.getId() = 7534
有人可以解释一下:
1)即使我setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
在下一行设置了日志显示优先级5
。为什么?
2)-8
第二个线程的优先级输出来自哪里?
3)10
新线程的来源也来自哪里?
更新:
如果我删除该行Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
输出保持不变