在 Android 中授予线程低优先级
如果我想授予线程低优先级,正确的调用是什么?
Thread t= new Thread(r);
t.setPriority(Thread.MIN_PRIORITY);
或者
Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
或者也许我应该将两者结合起来?如果是的话,这个调用的顺序很重要吗?谢谢
If I want grant a Thread a low priority whats the correct call?
Thread t= new Thread(r);
t.setPriority(Thread.MIN_PRIORITY);
or
Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
Or maybe should I combine both? If yes is the order of this calls important? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
t.setPriority(int)
将设置Thread t
的优先级。这不能用于将线程的优先级设置为高于接收者的ThreadGroup
。Process.setThreadPriority(int, int) 需要一个附加参数,以便您可以在任何线程上设置优先级(前提是不抛出 SecurityException)。
另请注意
Thread.MIN_PRIORITY
(1) 和Process.THREAD_PRIORITY_LOWEST
(19) 的整数值。t.setPriority(int)
will set the priority onThread t
. This can not be used to set a Thread's priority higher than the receiver'sThreadGroup
.Process.setThreadPriority(int, int)
takes an additional argument, so that you can set the priority on any Thread (granted aSecurityException
is not thrown).Also notice the integer value of
Thread.MIN_PRIORITY
(1) andProcess.THREAD_PRIORITY_LOWEST
(19).