linux java.policy_java – 实现Linux JVM实际上线程优先级?

那我们来看看

the source:

第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 code 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 code 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,否则您将看不到线程优先级。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值