Thread.setPriority()和android.os.Process.setThreadPriority()有什么区别 [英] What's the difference between Thread.setPriority() and android.os.Process.setThreadPriority()

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

问题描述

如果我有类似的代码:

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();
       }
    });

IS 是/首选android.os.Process方法?

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

为什么是android.os.Process的首选/要求方式?

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线程一一映射到底层Linux系统PTHREADs.所有应用程序的所有线程都属于系统上的同一线程组,因此每个线程都与所有应用程序的所有线程竞争.

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.

因此,当前Thread.setPriority实际上应该使用较小的Java优先级尺度与Process.setThreadPriority做相同的事情.优先级映射在kNiceValues中的 vm中定义/Thread.c

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

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

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