CN104424085A - Method for acquiring CPU (Central Processing Unit) and internal memory utilization rate of native machine based on JNI (Java Native Interface) - Google Patents

Method for acquiring CPU (Central Processing Unit) and internal memory utilization rate of native machine based on JNI (Java Native Interface) Download PDF

Info

Publication number
CN104424085A
CN104424085A CN201310402356.3A CN201310402356A CN104424085A CN 104424085 A CN104424085 A CN 104424085A CN 201310402356 A CN201310402356 A CN 201310402356A CN 104424085 A CN104424085 A CN 104424085A
Authority
CN
China
Prior art keywords
java
jni
internal memory
utilization rate
cpu
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201310402356.3A
Other languages
Chinese (zh)
Inventor
不公告发明人
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
ZHENJIANG JINRUAN COMPUTER TECHNOLOGY CO LTD
Original Assignee
ZHENJIANG JINRUAN COMPUTER TECHNOLOGY CO LTD
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by ZHENJIANG JINRUAN COMPUTER TECHNOLOGY CO LTD filed Critical ZHENJIANG JINRUAN COMPUTER TECHNOLOGY CO LTD
Priority to CN201310402356.3A priority Critical patent/CN104424085A/en
Publication of CN104424085A publication Critical patent/CN104424085A/en
Pending legal-status Critical Current

Links

Abstract

Under multiple conditions, the CPU (Central Processing Unit) and internal memory utilization rate of a native machine are quite important to Java application developers, and the developers can perfect and optimize an application by use of the CPU and internal memory utilization rate during application operation, so that better efficiency can be obtained, and more resources can be saved; furthermore the CPU and internal memory utilization rate is an important link for inspecting whether a Java application program achieves specific performances or not, but such information can not be directly obtained by Java. Therefore, if a user wants to acquire the information by use of Java, other technical means are required to be utilized to acquire the information, and the simplest and most convenient method is as follows: the acquired data is transmitted to Java by virtue of a JNI (Java Native Interface) by virtue of interaction of C language and an operation system at the bottom layer, so that the CPU and internal memory utilization rate of native machine can be acquired by a Java application.

Description

A kind of method obtaining the machine CPU and memory usage based on JNI
Technical field
The present invention relates to a kind of method obtaining the machine CPU and memory usage based on JNI.The invention belongs to field of computer technology.
Background technology
In many cases, the occupancy of the machine CPU and internal memory is very important concerning the developer that Java applies, it can Real-time Obtaining application current system CPU and service condition of internal memory when running, allow developer understand better application impact that system resource is caused, thus improvement and optimization makes application obtain better efficiency, save more resource, meanwhile, this is also check whether java application reaches an important step of particular characteristic.But these information are operating system internal informations, will obtain, and Java can not get the information of operating system from operating system.So, Java is used to get these information if want, just need by using other technologies means to obtain, the easiest and be exactly effectively bottom by C language and operating system mutual, the data got by JNI(Java Native Interface, Java native interface) be transferred to Java, thus make Java apply the occupancy that can get the machine CPU and internal memory.
Summary of the invention
According to the portable ability of Java standard, be the information that cannot get in these operating systems of occupancy of the machine CPU and internal memory.Choice for use JNI, bottom by C language and operating system mutual, the data got by JNI(Java Native Interface, Java native interface) be transferred to Java, Java just can be made to apply the occupancy that can get the machine CPU and internal memory.
Concrete steps are as follows:
Step 1: definition Java interface.A corresponding interface of parameter.
Step 2: generate JNI header file.Use Javah Program Generating JNI header file.
Step 3: add header file and library file.Add required header file and library file.
Step 4: codes implement.Write the acquisition of codes implement to system data.Compile successfully and will produce the dll file identical with project name.
Step 5: introduce and realize bag.Java is used to introduce the dll file of previous step generation.
Step 6: call Java interface, obtains gained system data.
Embodiment
Embodiment one
1. use Myeclips 8.6 development platform to develop design, use expert data library software MySql to carry out data management.
2. define two Java interfaces, obtain CPU usage and memory usage respectively.
3. generate JNI header file.Open order line, use javah program (%JAVA_HOME% bin javah) to generate JNI header file.javah -classpath ./bin com.getCpu.jni.SysInfo。This will generate the header file of a com.getCpu.jni.SysInfo.h under catalogue.
4. add header file and library file.Add the JNI header file that previous step generates, and the required library file such as jvm.lib.
5. realize respectively obtaining system CPU occupancy rate and memory usage by C language code.
6. get acquired system data information by calling Java interface.
In addition to the implementation, the present invention can also have other embodiments.All employings are equal to the technical scheme of replacement or equivalent transformation formation, all drop on the protection domain of application claims.

Claims (5)

1. define two Java interfaces, obtain CPU usage and memory usage respectively.
2. generate JNI header file; Open order line, use javah program (%JAVA_HOME% bin javah) to generate JNI header file.
3. add header file and library file; Add the JNI header file that previous step generates, and the required library file such as jvm.lib.
4. realize respectively obtaining system CPU occupancy rate and memory usage by C language code.
5. get acquired system data information by calling Java interface.
CN201310402356.3A 2013-09-07 2013-09-07 Method for acquiring CPU (Central Processing Unit) and internal memory utilization rate of native machine based on JNI (Java Native Interface) Pending CN104424085A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310402356.3A CN104424085A (en) 2013-09-07 2013-09-07 Method for acquiring CPU (Central Processing Unit) and internal memory utilization rate of native machine based on JNI (Java Native Interface)

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310402356.3A CN104424085A (en) 2013-09-07 2013-09-07 Method for acquiring CPU (Central Processing Unit) and internal memory utilization rate of native machine based on JNI (Java Native Interface)

Publications (1)

Publication Number Publication Date
CN104424085A true CN104424085A (en) 2015-03-18

Family

ID=52973132

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310402356.3A Pending CN104424085A (en) 2013-09-07 2013-09-07 Method for acquiring CPU (Central Processing Unit) and internal memory utilization rate of native machine based on JNI (Java Native Interface)

Country Status (1)

Country Link
CN (1) CN104424085A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2021056708A1 (en) * 2019-09-23 2021-04-01 平安科技(深圳)有限公司 Mass data import method and apparatus, computer device, and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101917286A (en) * 2010-07-30 2010-12-15 上海普元信息技术股份有限公司 Web performance analysis system and method for realizing cross-browser in internet application system
CN102830785A (en) * 2011-06-17 2012-12-19 上海果壳电子有限公司 Quick response system for equipment end input interaction and implementation method thereof
CN103279382A (en) * 2013-04-27 2013-09-04 北京微云即趣科技有限公司 Method, Java terminal, native terminal and system for native resource access

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101917286A (en) * 2010-07-30 2010-12-15 上海普元信息技术股份有限公司 Web performance analysis system and method for realizing cross-browser in internet application system
CN102830785A (en) * 2011-06-17 2012-12-19 上海果壳电子有限公司 Quick response system for equipment end input interaction and implementation method thereof
CN103279382A (en) * 2013-04-27 2013-09-04 北京微云即趣科技有限公司 Method, Java terminal, native terminal and system for native resource access

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
YUUKASKY: "JNI实现对CPU使用率的获取", 《博客频道》 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2021056708A1 (en) * 2019-09-23 2021-04-01 平安科技(深圳)有限公司 Mass data import method and apparatus, computer device, and storage medium

Similar Documents

Publication Publication Date Title
CN110187912B (en) Node selection method and device
CN101930400B (en) SDK (Software Development Kit) automatic test system and method
EP2893443B1 (en) Re-configuration in cloud computing environments
US20240054366A1 (en) AI Application Deployment Method and Related Platform, Cluster, Medium, and Program Product
US10725893B2 (en) System and method for determination of code coverage for software applications in a network environment
CN111061464B (en) Analysis code generation method, device, equipment and storage medium
CN104636122B (en) The sharing method and equipment of a kind of capability component
CN110795181A (en) Application program interface display method and device based on skip protocol and electronic equipment
CN103257852A (en) Method and device for building development environment of distributed application system
CN110955434B (en) Software development kit processing method and device, computer equipment and storage medium
La et al. A taxonomy of offloading in mobile cloud computing
CN111427557A (en) Application microservice method and device, electronic equipment and readable storage medium
Justino et al. Outsourcing resource-intensive tasks from mobile apps to clouds: Android and aneka integration
CN106610845B (en) Information management method, device, server and system
CN111797025B (en) Application-oriented data processing method and device
JP2005228183A (en) Program execution method and computer system for executing the program
US20230367936A1 (en) Verification method, electronic device and storage medium
Iyer et al. Extending android application programming framework for seamless cloud integration
CN104424085A (en) Method for acquiring CPU (Central Processing Unit) and internal memory utilization rate of native machine based on JNI (Java Native Interface)
TW201407503A (en) System and method for work schedule of cloud platform
US9172395B2 (en) Generating an ICONV module in real time
CN114567571B (en) Performance test method, device, electronic equipment and computer readable storage medium
CN103294874B (en) For Web service method for packing and the system of Electromagnetic Simulation computing system FEKO
US20150032789A1 (en) Dynamic object oriented remote instantiation
CN113485894A (en) Data acquisition method, device and equipment and readable storage medium

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20150318