• Post Reply Bookmark Topic Watch Topic
  • New Topic

% Used CPU  RSS feed

 
Marcos Loiola
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !!!
Is it possible to get the percent used by CPU from a java code ???
Thanks a lot
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IF your operating system provides a command line utility that can list processes etc. - you can execute it with exec(), catch the output stream and parse it. In Windows XP (?other versions?) type the following at a command prompt:
typeperf /?

Bill
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java 5 or later, see JConsole. The APIs it uses are available to you, too. I'd keep this kind of thing in a separate monitor application and not embed it in a real business app. Probably.
 
Henry Wong
author
Sheriff
Posts: 23291
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The information obtained by JConsole is obtained via the JMX API -- basically, java 5 JVM includes a built-in mbean server. This means any external program can obtain an mbean server connection to get the same information.

The internal application (code running in the JVM) can obtain the mxbeans directly via the ManagementFactory class -- which is much easier than using an mbean server connector.

See this tutorial for more information.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!