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

前端 未结 3 494
臣服心动
臣服心动 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-23 00:03

    I would rely on thread.setPriority(). The android.os.Process.setThreadPriority names a real thread priority of the underliying linux OS. However, those could, but doesn't need to map to Dalvik / Java VM threads, as the VM could do threading on its own means or use system threads or a combination of both. Raising the system priority would more likely result in prioritizing your application in favor of others, if not restricted by android security constraints, but not guarantee prioritizing your current Java Thread in favor of other Java Threads in your application.

提交回复
热议问题