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

If I have code like:

Runnable r = ...; Thread thread = new Thread(r); thread.setPriority((Thread.MAX_PRIORITY + Thread.NORM_PRIORITY) / 2); 

or...

  Runnable r = ... Thread thread = new Thread( new Runnable() { public void run() { android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_MORE_FAVORABLE); r.run(); } }); 

IS . Need / preferred android.os.Process method?

WHY is android.os.Process's preferred / mandatory way, if any?

This is not clearly documented as far as I can tell.

+67
android
Mar 04 2018-11-11T00:
source share
3 answers

The current Dalvik implementation seems to map Java streams one by one to the underlying PTHREAD Linux systems, as you said. All threads of all applications belong to the same thread group in the system, so each thread competes with all threads of all applications.

Therefore, at present, Thread.setPriority should do the same as Process.setThreadPriority , using a smaller Java priority scale. Priority mapping is defined in kNiceValues in vm / Thread.c

+33
Apr 15 2018-11-11T00:
source share

Google uses

 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); 

in the Volley Network Dispatcher section, so I believe that using the Process.setThreadPriority () method is the way to go.

+6
Aug 11 '14 at 5:22
source share

I would rely on thread.setPriority() . android.os.Process.setThreadPriority denotes the real thread priority for Linux with a basic level. However, they can, but should not, appear in Dalvik / Java VM threads, as the virtual machine can execute threads as it sees fit or use system threads or a combination of them. Raising the priority of the system is likely to prioritize your application in favor of others, if not limited by security restrictions for Android, but does not guarantee the priority of your current Java thread in favor of other Java threads in your application.

+1
Apr 15 2018-11-11T00:
source share



All Articles