java.lang.Thread.setPriority vs android.os.Process.setThreadPriority
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java.lang.Thread.setPriority vs android.os.Process.setThreadPriority,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1689字,纯文字阅读大概需要3分钟。
内容图文
![java.lang.Thread.setPriority vs android.os.Process.setThreadPriority](/upload/InfoBanner/zyjiaocheng/817/47073fa9211f4800a18a03d5bc32a387.jpg)
java.lang.Thread.setPriority和android.os.Process.setThreadPriority
他们有什么不同?
首先,在java.lang.Thread类中,
java.lang.Thread.setPriority(int priority)
priority可以具有Thread.MIN_PRIORITY(= 1,最低)到Thread.MAX_PRIORITY(= 10,Highest)的值.
java.lang.Thread类中有相关的常量.
public static final int MIN_PRIORITY = 1;
public static final int NORM_PRIORITY = 5;
public static final int MAX_PRIORITY = 10;
第二,在android.os.Process类中,
android.os.Process.setThreadPriority(int priority)
优先级可以是-20(最高)到19(最低)的值.
android.os.Process类中有相关的常量.
public static final int THREAD_PRIORITY_AUDIO = -16;
public static final int THREAD_PRIORITY_BACKGROUND = 10;
public static final int THREAD_PRIORITY_DEFAULT = 0;
public static final int THREAD_PRIORITY_DISPLAY = -4;
public static final int THREAD_PRIORITY_FOREGROUND = -2;
public static final int THREAD_PRIORITY_LESS_FAVORABLE = 1;
public static final int THREAD_PRIORITY_LOWEST = 19;
public static final int THREAD_PRIORITY_MORE_FAVORABLE = -1;
public static final int THREAD_PRIORITY_URGENT_AUDIO = -19;
public static final int THREAD_PRIORITY_URGENT_DISPLAY = -8;
我发现优先级值不同,但我不知道为什么.我不知道他们的工作方式有何不同.
解决方法:
How are they different?
Thread.setPriority仅适用于Java Thread对象;即当前JVM中的线程.相比之下,Process.setThreadPriority的javadoc表示它适用于线程和进程.由于线程/进程由tid值标识,因此它们不需要驻留在当前JVM中.
优先级值也不同,但不太重要. (在Thread的情况下,值被映射到平台的本机线程/进程优先级.在Process案例中,值是Linux平台的线程/进程优先级的本机.)
I don’t know how they work differently.
如果您将上述差异分解出来,它们的工作方式相同. AFAIK,所有现代主流JVM都依赖于本机平台线程调度程序及其优先级排序机制.
内容总结
以上是互联网集市为您收集整理的java.lang.Thread.setPriority vs android.os.Process.setThreadPriority全部内容,希望文章能够帮你解决java.lang.Thread.setPriority vs android.os.Process.setThreadPriority所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。