What's the difference between Thread.setPriority() and android.os.Process.setThreadPriority()

前端 未结 3 480
臣服心动
臣服心动 2020-12-22 23:45

If I have code like:

Runnable r = ...;

Thread  thread = new Thread(r);
thread.setPriority((Thread.MAX_PRIORITY + Thread.NORM_PRIORITY) / 2);
3条回答
  •  暖寄归人
    2020-12-22 23:58

    The current Dalvik implementation seems to map Java Threads one by one to the underlying linux system PTHREADs like you say. All Threads of all apps belong to the same thread group on the system, so every Thread competes with all Threads of all apps.

    So currently Thread.setPriority should actually do the same thing as Process.setThreadPriority, using the smaller Java priority scale. The mapping of priorities is defined in kNiceValues at vm/Thread.c

提交回复
热议问题