⑴ java如何获取系统内存、cpu等信息。
亲.java的目录下有一个demo文件夹,里面有很多范例,其中就有读取cpu信息,望采纳点赞谢谢
⑵ java windows怎么查看线程占用cpu
1、首先mp出该进程的所有线程及状态使用命令jstackPID命令打印出CPU占用过高进程的线程栈.jstack-l5683>5683.stack将进程id为5683的线程栈输出到了文件2、使用top命令找到耗cpu的线程使用top-H-pPID命令查看对应进程是哪个线程占
⑶ java能利用多核cpu吗
java线程可以在运行在多个cpu核上。
"在具有多个处理器的机器上,每一个处理器运行一个线程,可以有多个线程并行运行。当然,如果线程的数目多于处理器的数目,调度器依然采用时间片机制"。
现代os都将线程作为最小调度单位,进程作为资源分配的最小单位。 在windows中进程是不活动的,
只是作为线程的容器。
也就是说,java中的所有线程确实在JVM进程中,但是CPU调度的是进程中的线程。
"在具有多个处理器的机器上,每一个处理器运行一个线程,可以有多个线程并行运行。当然,如果线程的数目多于处理器的数目,调度器依然采用时间片机制"。这句话足以用来反驳那个出问题的人了,因为他的答案本身就是错的。
更详细的信息可以参见有关Java虚拟机实现的“并发”系列讲解,基本上每本关于Java虚拟机有关的书籍以及官方文档都会讲到JVM如何实现线程的几种方式。 基于系统内核,基于用户线程等等实现。JVM中的线程实现是本地化的~ 本地化的意思就是与平台有关了,尽管与平台有关,但是线程调度,仍旧是最佳高效的方式,有资料曾说过:线程的创建销毁与调度的开销是进程的三十分之一。
⑷ 最新java编程软件需要什么样的电脑配置CPU有什么要求能带的起来学习,办工用的笔记本电脑求推荐
您可以尝试一下搭载了第六代智能英特尔酷睿处理器的产品,无缝融合的英特尔锐炬显卡及核芯显卡,小身材,大能量,澎湃性能的同时兼具酷冷低耗,惊人电池续航表现,3D应用及多媒体视觉体验无与伦比,硬件级加速,完美畅享超高清4K视频编码及照片,同时支持栩栩如生的1080p高清视屏聊天。
全新一代锐炬Pro及锐炬显卡,CPU内部新增图形专用高速EDRAM缓存,带来媲美中高端独显的极致游戏体验。
Dell XPS 15 轻薄 SKL-H 15" Consumer 25-Oct
HP Spectre x360 2in1 i5/i7 Skylake 13" windows10
Dell Ins13BR-1708T I7-6500U SKL-U 13" Consumer 30-Sep
⑸ 怎么确定是否java程序一直只占用两个cpu 而不是同时利用48个cpu
是的,你判断的没有错,任务管理器---详细信息---JAVA程序点右键----设置相关性里,你分配下CPU内核,对比下就知道了。2个内核没有跑满,软件又没有优化的好,结果就是堵着1-2个内核使劲跑,其他内核全程打酱油了。狠常见的,毕竟多线程编程更复杂些,成本也更高。
⑹ windows下一个java进程如何同时使用多个cpu
这个程序只能占用一个cpu
⑺ 请问Java中获得CPU使用率的办法windows系统
1、确定当前系统安装的jdk是1.6版本以上
2、windows系统中有获取cpu使用率的可执行文件exe,只要在java中获取该文件的执行路径,通过Java调用即可。
3、获取操作系统可执行文件目录procCmd
4、调用java的Runtime.getRuntime().exec执行cmd应用程序
5、利用java中sleep来计算睡眠前后cpu的忙碌时间与空闲时间,因为sleep不会释放系统资源
6、根据忙碌时间占总时间的比例来计算cpu使用率
示例:
(){
try{
StringprocCmd=System.getenv("windir")
+"//system32//wbem//wmic.exeprocessgetCaption,CommandLine,"
+"KernelModeTime,ReadOperationCount,ThreadCount,UserModeTime,WriteOperationCount";
//取进程信息
long[]c0=readCpu(Runtime.getRuntime().exec(procCmd));
Thread.sleep(CPUTIME);
long[]c1=readCpu(Runtime.getRuntime().exec(procCmd));
if(c0!=null&&c1!=null){
longidletime=c1[0]-c0[0];
longbusytime=c1[1]-c0[1];
returnDouble.valueOf(
PERCENT*(busytime)/(busytime+idletime))
.doubleValue();
}else{
return0.0;
}
}catch(Exceptionex){
ex.printStackTrace();
return0.0;
}
}
⑻ java 怎么查看服务器的CPU使用率
1、确定当前系统安装的jdk是1.6版本以上
2、windows系统中有获取cpu使用率的可执行文件exe,只要在java中获取该文件的执行路径,通过Java调用即可。
3、获取操作系统可执行文件目录procCmd
4、调用java的Runtime.getRuntime().exec执行cmd应用程序
5、利用java中sleep来计算睡眠前后cpu的忙碌时间与空闲时间,因为sleep不会释放系统资源
6、根据忙碌时间占总时间的比例来计算cpu使用率!
⑼ Java如何读取CPU的数据信息
java获取所有系统信息(CPU、内存、进程等)的代码:
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.List;
import mytools.com.sun.management.OperatingSystemMXBean;
import mytools.java.io.File;
import mytools.java.lang.management.ManagementFactory;
/**
* 获取windows系统信息(CPU,内存,文件系统)
* @author libing
*
*/
public class WindowsInfoUtil {
private static final int CPUTIME = 500;
private static final int PERCENT = 100;
private static final int FAULTLENGTH = 10;
public static void main(String[] args) {
System.out.println(getCpuRatioForWindows());
System.out.println(getMemery());
System.out.println(getDisk());
}
//获取内存使用率
public static String getMemery(){
OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
// 总的物理内存+虚拟内存
long totalvirtualMemory = osmxb.getTotalSwapSpaceSize();
// 剩余的物理内存
long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize();
Double compare=(Double)(1-freePhysicalMemorySize*1.0/totalvirtualMemory)*100;
String str="内存已使用:"+compare.intValue()+"%";
return str;
}
//获取文件系统使用率
public static List<String> getDisk() {
// 操作系统
List<String> list=new ArrayList<String>();
for (char c = 'A'; c <= 'Z'; c++) {
String dirName = c + ":/";
File win = new File(dirName);
if(win.exists()){
long total=(long)win.getTotalSpace();
long free=(long)win.getFreeSpace();
Double compare=(Double)(1-free*1.0/total)*100;
String str=c+":盘 已使用 "+compare.intValue()+"%";
list.add(str);
}
}
return list;
}
//获得cpu使用率
public static String getCpuRatioForWindows() {
try {
String procCmd = System.getenv("windir") + "\\system32\\wbem\\wmic.exe process get Caption,CommandLine,KernelModeTime,ReadOperationCount,ThreadCount,UserModeTime,WriteOperationCount";
// 取进程信息
long[] c0 = readCpu(Runtime.getRuntime().exec(procCmd));
Thread.sleep(CPUTIME);
long[] c1 = readCpu(Runtime.getRuntime().exec(procCmd));
if (c0 != null && c1 != null) {
long idletime = c1[0] - c0[0];
long busytime = c1[1] - c0[1];
return "CPU使用率:"+Double.valueOf(PERCENT * (busytime)*1.0 / (busytime + idletime)).intValue()+"%";
} else {
return "CPU使用率:"+0+"%";
}
} catch (Exception ex) {
ex.printStackTrace();
return "CPU使用率:"+0+"%";
}
}
//读取cpu相关信息
private static long[] readCpu(final Process proc) {
long[] retn = new long[2];
try {
proc.getOutputStream().close();
InputStreamReader ir = new InputStreamReader(proc.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String line = input.readLine();
if (line == null || line.length() < FAULTLENGTH) {
return null;
}
int capidx = line.indexOf("Caption");
int cmdidx = line.indexOf("CommandLine");
int rocidx = line.indexOf("ReadOperationCount");
int umtidx = line.indexOf("UserModeTime");
int kmtidx = line.indexOf("KernelModeTime");
int wocidx = line.indexOf("WriteOperationCount");
long idletime = 0;
long kneltime = 0;
long usertime = 0;
while ((line = input.readLine()) != null) {
if (line.length() < wocidx) {
continue;
}
// 字段出现顺序:Caption,CommandLine,KernelModeTime,ReadOperationCount,
// ThreadCount,UserModeTime,WriteOperation
String caption =substring(line, capidx, cmdidx - 1).trim();
String cmd = substring(line, cmdidx, kmtidx - 1).trim();
if (cmd.indexOf("wmic.exe") >= 0) {
continue;
}
String s1 = substring(line, kmtidx, rocidx - 1).trim();
String s2 = substring(line, umtidx, wocidx - 1).trim();
if (caption.equals("System Idle Process") || caption.equals("System")) {
if (s1.length() > 0)
idletime += Long.valueOf(s1).longValue();
if (s2.length() > 0)
idletime += Long.valueOf(s2).longValue();
continue;
}
if (s1.length() > 0)
kneltime += Long.valueOf(s1).longValue();
if (s2.length() > 0)
usertime += Long.valueOf(s2).longValue();
}
retn[0] = idletime;
retn[1] = kneltime + usertime;
return retn;
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
proc.getInputStream().close();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
/**
* 由于String.subString对汉字处理存在问题(把一个汉字视为一个字节),因此在 包含汉字的字符串时存在隐患,现调整如下:
* @param src 要截取的字符串
* @param start_idx 开始坐标(包括该坐标)
* @param end_idx 截止坐标(包括该坐标)
* @return
*/
private static String substring(String src, int start_idx, int end_idx) {
byte[] b = src.getBytes();
String tgt = "";
for (int i = start_idx; i <= end_idx; i++) {
tgt += (char) b[i];
}
return tgt;
}
}