- 浏览: 747889 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
梦行Monxin商城系统:
java网上商城与php网上商城比较 -
梦行Monxin商城系统:
java网上商城与php网上商城比较 -
任楚娴:
你好,请问html = nvl(html); 这句中的nvl( ...
java html串转换成文本串 -
u013246812:
,谢拉!
jQuery ui Dialog 讲解参数 -
大宝剑99:
...
前端优化
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.StringTokenizer;
import sun.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;
public class MonitorServiceImpl implements IMonitorService{
private static final int CPUTIME = 30;
private static final int PERCENT = 100;
private static final int FAULTLENGTH = 10;
private static final File versionFile = new File("/proc/version");
private static String linuxVersion = null;
/**
* 获得当前的监控对象.
* @return 返回构造好的监控对象
* @throws Exception
* @author GuoHuang
*/
public MonitorInfoBean getMonitorInfoBean() throws Exception {
int kb = 1024;
// 可使用内存
long totalMemory = Runtime.getRuntime().totalMemory() / kb;
// 剩余内存
long freeMemory = Runtime.getRuntime().freeMemory() / kb;
// 最大可使用内存
long maxMemory = Runtime.getRuntime().maxMemory() / kb;
OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory
.getOperatingSystemMXBean();
// 操作系统
String osName = System.getProperty("os.name");
// 总的物理内存
long totalMemorySize = osmxb.getTotalPhysicalMemorySize() / kb;
// 剩余的物理内存
long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize() / kb;
// 已使用的物理内存
long usedMemory = (osmxb.getTotalPhysicalMemorySize() - osmxb
.getFreePhysicalMemorySize())
/ kb;
// 获得线程总数
ThreadGroup parentThread;
for (parentThread = Thread.currentThread().getThreadGroup(); parentThread
.getParent() != null; parentThread = parentThread.getParent())
;
int totalThread = parentThread.activeCount();
double cpuRatio = 0;
if (osName.toLowerCase().startsWith("windows")) {
cpuRatio = this.getCpuRatioForWindows();
}
else {
cpuRatio = this.getCpuRateForLinux();
}
// 构造返回对象
MonitorInfoBean infoBean = new MonitorInfoBean();
infoBean.setFreeMemory(freeMemory);
infoBean.setFreePhysicalMemorySize(freePhysicalMemorySize);
infoBean.setMaxMemory(maxMemory);
infoBean.setOsName(osName);
infoBean.setTotalMemory(totalMemory);
infoBean.setTotalMemorySize(totalMemorySize);
infoBean.setTotalThread(totalThread);
infoBean.setUsedMemory(usedMemory);
infoBean.setCpuRatio(cpuRatio);
return infoBean;
}
private static double getCpuRateForLinux(){
InputStream is = null;
InputStreamReader isr = null;
BufferedReader brStat = null;
StringTokenizer tokenStat = null;
try{
System.out.println("Get usage rate of CUP , linux version: "+linuxVersion);
Process process = Runtime.getRuntime().exec("top -b -n 1");
is = process.getInputStream();
isr = new InputStreamReader(is);
brStat = new BufferedReader(isr);
if(linuxVersion.equals("2.4")){
brStat.readLine();
brStat.readLine();
brStat.readLine();
brStat.readLine();
tokenStat = new StringTokenizer(brStat.readLine());
tokenStat.nextToken();
tokenStat.nextToken();
String user = tokenStat.nextToken();
tokenStat.nextToken();
String system = tokenStat.nextToken();
tokenStat.nextToken();
String nice = tokenStat.nextToken();
System.out.println(user+" , "+system+" , "+nice);
user = user.substring(0,user.indexOf("%"));
system = system.substring(0,system.indexOf("%"));
nice = nice.substring(0,nice.indexOf("%"));
float userUsage = new Float(user).floatValue();
float systemUsage = new Float(system).floatValue();
float niceUsage = new Float(nice).floatValue();
return (userUsage+systemUsage+niceUsage)/100;
}else{
brStat.readLine();
brStat.readLine();
tokenStat = new StringTokenizer(brStat.readLine());
tokenStat.nextToken();
tokenStat.nextToken();
tokenStat.nextToken();
tokenStat.nextToken();
tokenStat.nextToken();
tokenStat.nextToken();
tokenStat.nextToken();
String cpuUsage = tokenStat.nextToken();
System.out.println("CPU idle : "+cpuUsage);
Float usage = new Float(cpuUsage.substring(0,cpuUsage.indexOf("%")));
return (1-usage.floatValue()/100);
}
} catch(IOException ioe){
System.out.println(ioe.getMessage());
freeResource(is, isr, brStat);
return 1;
} finally{
freeResource(is, isr, brStat);
}
}
private static void freeResource(InputStream is, InputStreamReader isr, BufferedReader br){
try{
if(is!=null)
is.close();
if(isr!=null)
isr.close();
if(br!=null)
br.close();
}catch(IOException ioe){
System.out.println(ioe.getMessage());
}
}
/**
* 获得CPU使用率.
* @return 返回cpu使用率
* @author GuoHuang
*/
private double 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 Double.valueOf(
PERCENT * (busytime) / (busytime + idletime))
.doubleValue();
} else {
return 0.0;
}
} catch (Exception ex) {
ex.printStackTrace();
return 0.0;
}
}
/**
* 读取CPU信息.
* @param proc
* @return
* @author GuoHuang
*/
private 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 = Bytes.substring(line, capidx, cmdidx - 1)
.trim();
String cmd = Bytes.substring(line, cmdidx, kmtidx - 1).trim();
if (cmd.indexOf("wmic.exe") >= 0) {
continue;
}
// log.info("line="+line);
if (caption.equals("System Idle Process")
|| caption.equals("System")) {
idletime += Long.valueOf(
Bytes.substring(line, kmtidx, rocidx - 1).trim())
.longValue();
idletime += Long.valueOf(
Bytes.substring(line, umtidx, wocidx - 1).trim())
.longValue();
continue;
}
kneltime += Long.valueOf(
Bytes.substring(line, kmtidx, rocidx - 1).trim())
.longValue();
usertime += Long.valueOf(
Bytes.substring(line, umtidx, wocidx - 1).trim())
.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;
}
public static void main(String[] args) throws Exception{
IMonitorService service = new MonitorServiceImpl();
MonitorInfoBean monitorInfo = service.getMonitorInfoBean();
System.out.println("cpu占有率=" + monitorInfo.getCpuRatio());
System.out.println("可使用内存=" + monitorInfo.getTotalMemory());
System.out.println("剩余内存=" + monitorInfo.getFreeMemory());
System.out.println("最大可使用内存=" + monitorInfo.getMaxMemory());
System.out.println("操作系统=" + monitorInfo.getOsName());
System.out.println("总的物理内存=" + monitorInfo.getTotalMemorySize() + "kb");
System.out.println("剩余的物理内存=" + monitorInfo.getFreeMemory() + "kb");
System.out.println("已使用的物理内存=" + monitorInfo.getUsedMemory() + "kb");
System.out.println("线程总数=" + monitorInfo.getTotalThread() + "kb");
}
}
class Bytes {
public 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;
}
}
class MonitorInfoBean {
/** 可使用内存. */
private long totalMemory;
/** 剩余内存. */
private long freeMemory;
/** 最大可使用内存. */
private long maxMemory;
/** 操作系统. */
private String osName;
/** 总的物理内存. */
private long totalMemorySize;
/** 剩余的物理内存. */
private long freePhysicalMemorySize;
/** 已使用的物理内存. */
private long usedMemory;
/** 线程总数. */
private int totalThread;
/** cpu使用率. */
private double cpuRatio;
public long getFreeMemory() {
return freeMemory;
}
public void setFreeMemory(long freeMemory) {
this.freeMemory = freeMemory;
}
public long getFreePhysicalMemorySize() {
return freePhysicalMemorySize;
}
public void setFreePhysicalMemorySize(long freePhysicalMemorySize) {
this.freePhysicalMemorySize = freePhysicalMemorySize;
}
public long getMaxMemory() {
return maxMemory;
}
public void setMaxMemory(long maxMemory) {
this.maxMemory = maxMemory;
}
public String getOsName() {
return osName;
}
public void setOsName(String osName) {
this.osName = osName;
}
public long getTotalMemory() {
return totalMemory;
}
public void setTotalMemory(long totalMemory) {
this.totalMemory = totalMemory;
}
public long getTotalMemorySize() {
return totalMemorySize;
}
public void setTotalMemorySize(long totalMemorySize) {
this.totalMemorySize = totalMemorySize;
}
public int getTotalThread() {
return totalThread;
}
public void setTotalThread(int totalThread) {
this.totalThread = totalThread;
}
public long getUsedMemory() {
return usedMemory;
}
public void setUsedMemory(long usedMemory) {
this.usedMemory = usedMemory;
}
public double getCpuRatio() {
return cpuRatio;
}
public void setCpuRatio(double cpuRatio) {
this.cpuRatio = cpuRatio;
}
}
interface IMonitorService {
public MonitorInfoBean getMonitorInfoBean() throws Exception;
}
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.StringTokenizer;
import sun.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;
public class MonitorServiceImpl implements IMonitorService{
private static final int CPUTIME = 30;
private static final int PERCENT = 100;
private static final int FAULTLENGTH = 10;
private static final File versionFile = new File("/proc/version");
private static String linuxVersion = null;
/**
* 获得当前的监控对象.
* @return 返回构造好的监控对象
* @throws Exception
* @author GuoHuang
*/
public MonitorInfoBean getMonitorInfoBean() throws Exception {
int kb = 1024;
// 可使用内存
long totalMemory = Runtime.getRuntime().totalMemory() / kb;
// 剩余内存
long freeMemory = Runtime.getRuntime().freeMemory() / kb;
// 最大可使用内存
long maxMemory = Runtime.getRuntime().maxMemory() / kb;
OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory
.getOperatingSystemMXBean();
// 操作系统
String osName = System.getProperty("os.name");
// 总的物理内存
long totalMemorySize = osmxb.getTotalPhysicalMemorySize() / kb;
// 剩余的物理内存
long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize() / kb;
// 已使用的物理内存
long usedMemory = (osmxb.getTotalPhysicalMemorySize() - osmxb
.getFreePhysicalMemorySize())
/ kb;
// 获得线程总数
ThreadGroup parentThread;
for (parentThread = Thread.currentThread().getThreadGroup(); parentThread
.getParent() != null; parentThread = parentThread.getParent())
;
int totalThread = parentThread.activeCount();
double cpuRatio = 0;
if (osName.toLowerCase().startsWith("windows")) {
cpuRatio = this.getCpuRatioForWindows();
}
else {
cpuRatio = this.getCpuRateForLinux();
}
// 构造返回对象
MonitorInfoBean infoBean = new MonitorInfoBean();
infoBean.setFreeMemory(freeMemory);
infoBean.setFreePhysicalMemorySize(freePhysicalMemorySize);
infoBean.setMaxMemory(maxMemory);
infoBean.setOsName(osName);
infoBean.setTotalMemory(totalMemory);
infoBean.setTotalMemorySize(totalMemorySize);
infoBean.setTotalThread(totalThread);
infoBean.setUsedMemory(usedMemory);
infoBean.setCpuRatio(cpuRatio);
return infoBean;
}
private static double getCpuRateForLinux(){
InputStream is = null;
InputStreamReader isr = null;
BufferedReader brStat = null;
StringTokenizer tokenStat = null;
try{
System.out.println("Get usage rate of CUP , linux version: "+linuxVersion);
Process process = Runtime.getRuntime().exec("top -b -n 1");
is = process.getInputStream();
isr = new InputStreamReader(is);
brStat = new BufferedReader(isr);
if(linuxVersion.equals("2.4")){
brStat.readLine();
brStat.readLine();
brStat.readLine();
brStat.readLine();
tokenStat = new StringTokenizer(brStat.readLine());
tokenStat.nextToken();
tokenStat.nextToken();
String user = tokenStat.nextToken();
tokenStat.nextToken();
String system = tokenStat.nextToken();
tokenStat.nextToken();
String nice = tokenStat.nextToken();
System.out.println(user+" , "+system+" , "+nice);
user = user.substring(0,user.indexOf("%"));
system = system.substring(0,system.indexOf("%"));
nice = nice.substring(0,nice.indexOf("%"));
float userUsage = new Float(user).floatValue();
float systemUsage = new Float(system).floatValue();
float niceUsage = new Float(nice).floatValue();
return (userUsage+systemUsage+niceUsage)/100;
}else{
brStat.readLine();
brStat.readLine();
tokenStat = new StringTokenizer(brStat.readLine());
tokenStat.nextToken();
tokenStat.nextToken();
tokenStat.nextToken();
tokenStat.nextToken();
tokenStat.nextToken();
tokenStat.nextToken();
tokenStat.nextToken();
String cpuUsage = tokenStat.nextToken();
System.out.println("CPU idle : "+cpuUsage);
Float usage = new Float(cpuUsage.substring(0,cpuUsage.indexOf("%")));
return (1-usage.floatValue()/100);
}
} catch(IOException ioe){
System.out.println(ioe.getMessage());
freeResource(is, isr, brStat);
return 1;
} finally{
freeResource(is, isr, brStat);
}
}
private static void freeResource(InputStream is, InputStreamReader isr, BufferedReader br){
try{
if(is!=null)
is.close();
if(isr!=null)
isr.close();
if(br!=null)
br.close();
}catch(IOException ioe){
System.out.println(ioe.getMessage());
}
}
/**
* 获得CPU使用率.
* @return 返回cpu使用率
* @author GuoHuang
*/
private double 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 Double.valueOf(
PERCENT * (busytime) / (busytime + idletime))
.doubleValue();
} else {
return 0.0;
}
} catch (Exception ex) {
ex.printStackTrace();
return 0.0;
}
}
/**
* 读取CPU信息.
* @param proc
* @return
* @author GuoHuang
*/
private 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 = Bytes.substring(line, capidx, cmdidx - 1)
.trim();
String cmd = Bytes.substring(line, cmdidx, kmtidx - 1).trim();
if (cmd.indexOf("wmic.exe") >= 0) {
continue;
}
// log.info("line="+line);
if (caption.equals("System Idle Process")
|| caption.equals("System")) {
idletime += Long.valueOf(
Bytes.substring(line, kmtidx, rocidx - 1).trim())
.longValue();
idletime += Long.valueOf(
Bytes.substring(line, umtidx, wocidx - 1).trim())
.longValue();
continue;
}
kneltime += Long.valueOf(
Bytes.substring(line, kmtidx, rocidx - 1).trim())
.longValue();
usertime += Long.valueOf(
Bytes.substring(line, umtidx, wocidx - 1).trim())
.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;
}
public static void main(String[] args) throws Exception{
IMonitorService service = new MonitorServiceImpl();
MonitorInfoBean monitorInfo = service.getMonitorInfoBean();
System.out.println("cpu占有率=" + monitorInfo.getCpuRatio());
System.out.println("可使用内存=" + monitorInfo.getTotalMemory());
System.out.println("剩余内存=" + monitorInfo.getFreeMemory());
System.out.println("最大可使用内存=" + monitorInfo.getMaxMemory());
System.out.println("操作系统=" + monitorInfo.getOsName());
System.out.println("总的物理内存=" + monitorInfo.getTotalMemorySize() + "kb");
System.out.println("剩余的物理内存=" + monitorInfo.getFreeMemory() + "kb");
System.out.println("已使用的物理内存=" + monitorInfo.getUsedMemory() + "kb");
System.out.println("线程总数=" + monitorInfo.getTotalThread() + "kb");
}
}
class Bytes {
public 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;
}
}
class MonitorInfoBean {
/** 可使用内存. */
private long totalMemory;
/** 剩余内存. */
private long freeMemory;
/** 最大可使用内存. */
private long maxMemory;
/** 操作系统. */
private String osName;
/** 总的物理内存. */
private long totalMemorySize;
/** 剩余的物理内存. */
private long freePhysicalMemorySize;
/** 已使用的物理内存. */
private long usedMemory;
/** 线程总数. */
private int totalThread;
/** cpu使用率. */
private double cpuRatio;
public long getFreeMemory() {
return freeMemory;
}
public void setFreeMemory(long freeMemory) {
this.freeMemory = freeMemory;
}
public long getFreePhysicalMemorySize() {
return freePhysicalMemorySize;
}
public void setFreePhysicalMemorySize(long freePhysicalMemorySize) {
this.freePhysicalMemorySize = freePhysicalMemorySize;
}
public long getMaxMemory() {
return maxMemory;
}
public void setMaxMemory(long maxMemory) {
this.maxMemory = maxMemory;
}
public String getOsName() {
return osName;
}
public void setOsName(String osName) {
this.osName = osName;
}
public long getTotalMemory() {
return totalMemory;
}
public void setTotalMemory(long totalMemory) {
this.totalMemory = totalMemory;
}
public long getTotalMemorySize() {
return totalMemorySize;
}
public void setTotalMemorySize(long totalMemorySize) {
this.totalMemorySize = totalMemorySize;
}
public int getTotalThread() {
return totalThread;
}
public void setTotalThread(int totalThread) {
this.totalThread = totalThread;
}
public long getUsedMemory() {
return usedMemory;
}
public void setUsedMemory(long usedMemory) {
this.usedMemory = usedMemory;
}
public double getCpuRatio() {
return cpuRatio;
}
public void setCpuRatio(double cpuRatio) {
this.cpuRatio = cpuRatio;
}
}
interface IMonitorService {
public MonitorInfoBean getMonitorInfoBean() throws Exception;
}
发表评论
-
全国最新行政区划代码(Tree)json数据以及地理数据
2020-11-11 21:23 382基于阿里提供的地理数据 http://datav.aliyun ... -
小知识点--解锁 AppChecker ping ip
2019-06-19 08:40 442在使用AppChecker 进行主动拨测的时候,目 ... -
记录年会小系统
2018-02-04 14:42 1144有点意思,年会过后,抽奖活动saas小系统扒光看看:支持P ... -
jdbc方式以 sys账号连接oracle数据的问题
2017-08-22 10:44 484多年以后,在操作oracle 时 发现 jdbc 连 ... -
proguard 代码混淆
2016-11-22 10:59 692url:http://proguard.sourceforg ... -
solr 表达式意义
2015-02-03 19:29 7791. “:”指定字段查指定值,如返回所有值*:* 2. “? ... -
solr 安装配置
2015-02-03 13:15 747solr 安装配置步骤: 1 首先下载solr(最新 ... -
javax.net.ssl.SSLKeyException: RSA premaster secre临时解决方案
2014-11-25 19:38 4420javax.net.ssl.SSLKeyException ... -
compass 小知识点
2014-09-15 10:22 940今天发现排序不管事, 查了一下:索引的问题:排序的列不进 ... -
java_opts 常用
2014-08-14 13:16 1221JVM设置,可以查考如下配置example:# Memory ... -
RPC Socket 服务调用模型
2014-04-09 16:14 602最近在看Dubbo 服务框架, 通过RPC 实现了输入和 ... -
JVM 基本参数
2014-04-03 11:49 789基本的JVM参数:-classpath, -cp: 设置类搜 ... -
eclipse 快捷键失效解决方法
2014-01-17 17:20 722有时候eclispe快捷键失效了,编码起来太难受了。 ... -
Compass+ lucene 通用代码(脱离数据库)
2013-11-08 15:09 920最近需要通过检索分类的方式进行处理,所以就写了接口与实 ... -
DEBUG远程tomcat
2013-08-21 13:35 1003一、在windows系统中:打开%CATALINE_H ... -
自动获取网页内容,然后写入excel文档中
2013-07-05 15:22 3451今天需要将北京物业公司名称以及电话给整理出来,发现爱帮 ... -
继续学习jersey+spring 构建RESTful风格 webservice
2013-03-13 10:36 3462j先说一下springmvc rest风格 spring ... -
尽量少使用jaxb 进行xml与对象互换
2013-03-09 17:33 1354尽量少使用jaxb 进行xml与对象互换 问题不少,这个好 ... -
Cookie path的设置
2013-02-21 10:58 1952cookie path 设置 IE对如下的co ... -
http 相关知识点
2012-10-11 10:49 1066Host头域 Host头域指定请求资源的Intenet主机和 ...
相关推荐
在Java编程中,获取系统参数是一项基本任务,用于了解运行Java程序的环境信息。Java提供了`java.lang.System`类的`getProperties()`方法来获取这些信息。这个方法返回一个`Properties`对象,该对象包含了关于Java...
在Java编程语言中,开发人员经常需要访问与运行环境相关的各种系统参数,这些参数对于调试、配置以及确保程序兼容性等方面至关重要。通过Java内置的方法,我们可以轻松地获取一系列关于Java运行时环境(JRE)及操作...
java语言操作系统课程设计模拟进程管理系统源码 需求分析 实现n个进程并发运行; 实现进程创建、撤销、阻塞、唤醒; 实现进程的同步; 实现优先级调度、时间片轮转、短进程优先等调度算法; 系统在运行过程中应能...
Java作为一种广泛使用的编程语言,提供了处理WSDL文档的能力,帮助开发者获取服务中的方法和参数信息。本篇将深入探讨如何在Java中解析WSDL文档并提取关键细节。 首先,理解WSDL文档的结构至关重要。WSDL文档包含了...
总结,Java解析WSDL文档获取方法与参数涉及到的技术点包括:了解WSDL的基本概念,使用Apache CXF或其他类似库,加载和解析WSDL文档,获取服务、端点、操作和消息信息,最后可能还需要生成Java客户端代码以便于调用...
在Java编程语言中,获取并格式化系统当前时间是一项非常基础且常用的操作。本文档将详细介绍如何利用Java内置类来实现这一功能,并深入探讨其中涉及的重要概念和技术细节。 #### 一、核心概念 1. **`java.util....
本文将深入探讨如何使用Java来检测、识别并获取USB设备的相关信息。 首先,我们需要理解Java中处理USB设备的基本原理。由于Java标准库并没有内置对USB设备的直接支持,所以我们通常需要借助第三方库或者Java的JNI...
例如,`List<?>`的`Class`类型是`java.util.List`,这意味着你不能直接获取泛型的实际类型参数。然而,你可以通过类型检查和转换来操作List中的元素。 5. 访问私有成员: 对于私有字段和方法,可以使用`...
2. **文件系统**:不同的操作系统对于文件属性的支持程度不同。例如,在Windows系统中,文件的创建时间是可查询的;而在某些Linux发行版中,可能无法直接获取文件的创建时间。 #### 使用Java 7及更高版本获取文件...
在Java编程中,读取服务器硬件信息是一项重要的任务,尤其对于跨平台的应用程序来说,能够兼容Windows、Linux和Mac OS等不同操作系统是必不可少的。本文将深入探讨如何使用Java来获取这些不同系统的硬件信息。 首先...
Java SIGAR库是一个强大的工具,用于跨平台地获取操作系统级别的信息。这个项目示例主要展示了如何使用SIGAR库1.6版本来收集和分析本地系统的各种信息,包括JVM、内存、操作系统、文件系统和网络状态。以下是这些...
在Java编程环境中,调用Windows操作系统来实现文本转语音(Text-to-Speech, TTS)并生成播放文件是一项常见的需求。这项技术可以帮助开发者为应用程序添加语音合成功能,尤其适用于无障碍应用、语音助手或者多媒体...
总结来说,当Java获取的时间与实际相差8小时时,应检查JVM的时区设置以及操作系统时区设置。通过调整这两个层面的时区,可以确保Java程序获取到正确的时间。对于跨时区的应用,理解和正确使用时区处理是至关重要的,...
在Java编程中,有时我们需要获取Java虚拟机(JVM)的相关参数,比如内存使用情况、JVM启动参数等。这可以帮助我们监控应用性能、优化内存分配或者排查问题。以下是一些在Java代码中获取JVM参数的方法: 首先,我们...
JavaComm提供了一个API,允许Java程序通过串行和并行端口发送和接收数据,而RXTX是一个开源的Java库,提供了更全面的低级串行和并行通信功能,适用于多种操作系统。 1. **Java Communications API(JavaComm)**:...
Java IPMI(Intelligent Platform Management Interface)是一种标准的硬件管理接口,用于远程监控和管理系统硬件的状态,如服务器的温度、风扇速度、内存使用情况等。VxIPMI是基于Java的IPMI实现,它提供了方便的...
你需要读取这个Excel文件,使用Java的Apache POI库或者JExcelApi来解析,获取到对应地区的编码,然后用这些编码作为查询参数。 4. **高德地图API集成** 高德地图的天气API可能需要用户的位置信息,因此可能需要...
另外,`java.lang.management`包中的`OperatingSystemMXBean`接口提供了关于操作系统的管理信息,虽然它不能直接获取程序路径,但可以帮助了解程序运行的上下文。例如: ```java ManagementFactory....
在本文中,我们将介绍 Java 模拟 Cookie 登陆的简单操作,结合实例形式分析了 Java 模拟 Cookie 登陆的相关原理与基本实现技巧。本示例主要是为了演示如何使用 Java 语言模拟 Cookie 登陆,实现自动登陆的功能。 是...
Java提供了丰富的类库和方法来获取这些信息,主要包括JVM(Java虚拟机)信息、操作系统信息、系统属性以及类路径等。下面将详细阐述如何利用Java获取这些信息。 1. **JVM信息**: - 使用`java.lang.RuntimeMXBean`...