Java 如何将JVM绑定到特定的CPU核上

在Java 如何将JVM绑定到特定的CPU核上 ,C,C++都可以实现,那java呢?

要实现这个功能,必须使用JRockit JDK,它完全兼容SUN JDK,因为完全就是一家公司出的嘛。装完之后就有其类库了。

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.bea.jvm.*;

public class test1{
 
 public static void main(String[] args) {
  int count=0; //Record the count of cpus
  JVM jvm = JVMFactory.getJVM();
  List<CPU> cpus = new ArrayList<CPU>(); //To save the all cpu of system
  List<CPU> cpu_set = new ArrayList<CPU>(); //This cpu is used to bind the JVM
  for(Iterator it = JVMFactory.getJVM().getProcessAffinity().iterator();it.hasNext();count++)
  {
  CPU cpu = (CPU) it.next();
  cpus.add(cpu);  
  }
  System.out.println("The count of system cpu is " + count);
  cpu_set.add(cpus.get(2));
  jvm.suggestProcessAffinity(cpu_set);
  while(true);
 }
}

我的机子是inte core i5,具有4个CPU核,我将其绑在第三个核上,可以见下图:

运行后进程是javaw,点鼠标右键出来set affinity就可以看见了。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值