最新Thread.setPriority()和android.os.Process.setThreadPriority之间的差值() [英] Whats the difference between Thread.setPriority() and android.os.Process.setThreadPriority()

查看:660
本文介绍了最新Thread.setPriority()和android.os.Process.setThreadPriority之间的差值()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,如果我有code这样的:

So if I have code like:

Runnable r = ...;

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

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

所需android.os.Process方式/ preferred?

IS the android.os.Process way required/preferred?

为什么是android.os.Process方式preferred /如果需要?

WHY is the android.os.Process way preferred/required if it is?

这是没有明确的记载,据我可以告诉。

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

推荐答案

目前Dalvik的实现看起来像你说的映射Java线程ONY一个底层linux系统的pthreads。所有应用程序的所有线程属于同一个线程组的系统上,所以每一个线程竞争与所有应用程序的所有线程。

The current Dalvik implementation seems to map Java Threads ony 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.

所以,目前 Thread.setPriority 实际上应该做同样的 Process.setThreadPriority ,使用较小的Java优先级规模,优先级映射是在<定义的 kNiceValues​​ href="http://android.git.kernel.org/?p=platform/dalvik.git;a=blob;f=vm/Thread.c;h=c9b63112dfe19f141a915d60de30b8168df44964;hb=HEAD">vm/Thread.c

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

这篇关于最新Thread.setPriority()和android.os.Process.setThreadPriority之间的差值()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆