Android 线程的优先级

Android可以在当前线程中调用Process.setThreadPriority来设置当前的线程优先级,如下

Thread{
    Process.setThreadPriority(Process.THREAD_PRIORITY_AUDIO)
}.start()

看一下这个方法的注释

    /**
     * Set the priority of the calling thread, based on Linux priorities.  See
     * {@link #setThreadPriority(int, int)} for more information.
     * 
     * @param priority A Linux priority level, from -20 for highest scheduling
     * priority to 19 for lowest scheduling priority.
     * 
     * @throws IllegalArgumentException Throws IllegalArgumentException if
     * <var>tid</var> does not exist.
     * @throws SecurityException Throws SecurityException if your process does
     * not have permission to modify the given thread, or to use the given
     * priority.
     * 
     * @see #setThreadPriority(int, int)
     */

大意就是说这个可以设置线程的优先级,是基于Linux的线程优先级策略。

Android中常见的线程优先级有

int THREAD_PRIORITY_AUDIO //标准音乐播放使用的线程优先级

int THREAD_PRIORITY_BACKGROUND //标准后台程序

int THREAD_PRIORITY_DEFAULT // 默认应用的优先级

int THREAD_PRIORITY_DISPLAY //标准显示系统优先级,主要是改善UI的刷新

int THREAD_PRIORITY_FOREGROUND //标准前台线程优先级

int THREAD_PRIORITY_LESS_FAVORABLE //低于favorable

int THREAD_PRIORITY_LOWEST //有效的线程最低的优先级

int THREAD_PRIORITY_MORE_FAVORABLE //高于favorable

int THREAD_PRIORITY_URGENT_AUDIO //标准较重要音频播放优先级

int THREAD_PRIORITY_URGENT_DISPLAY //标准较重要显示优先级,对于输入事件同样适用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值