栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Linux JVM是否实际实现线程优先级?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux JVM是否实际实现线程优先级?

好吧,让我们看一下源代码:

2947行:

////////////////////////////////////////////////////////////////////////////////// thread priority support// Note: Normal Linux applications are run with SCHED_OTHER policy. SCHED_OTHER// only supports dynamic priority, static priority must be zero. For real-time// applications, Linux supports SCHED_RR which allows static priority (1-99).// However, for large multi-threaded applications, SCHED_RR is not only slower// than SCHED_OTHER, but also very unstable (my volano tests hang hard 4 out// of 5 runs - Sep 2005).//// The following pre actually changes the niceness of kernel-thread/LWP. It// has an assumption that setpriority() only modifies one kernel-thread/LWP,// not the entire user process, and user level threads are 1:1 mapped to kernel// threads. It has always been the case, but could change in the future. For// this reason, the pre should not be used as default (ThreadPriorityPolicy=0).// It is only used when ThreadPriorityPolicy=1 and requires root privilege.

第2982行:

 static int prio_init() {   if (ThreadPriorityPolicy == 1) {     // only root can raise thread priority. Don't allow ThreadPriorityPolicy=1     // if effective uid is not root. Perhaps, a more elegant way of doing     // this is to test CAP_SYS_NICE capability, but that will require libcap.so     if (geteuid() != 0) {       if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy)) {         warning("-XX:ThreadPriorityPolicy requires root privilege on Linux");       }       ThreadPriorityPolicy = 0;     }   }   return 0; }

第2997行:

OSReturn os::set_native_priority(Thread* thread, int newpri) {  if ( !UseThreadPriorities || ThreadPriorityPolicy == 0 ) return OS_OK;  int ret = setpriority(PRIO_PROCESS, thread->osthread()->thread_id(), newpri);  return (ret == 0) ? OS_OK : OS_ERR;}

所以!至少在Sun
Java和Linux上,除非您已经完成

-XX:ThreadPriorityPolicy
并且似乎需要root用户,否则您将看不到线程优先级。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/437789.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号