2

I see code for jdk6 that has the following OperatingSystemMXBean method :

OperatingSystemMXBean osbean = 
    (OperatingSystemMXBean)      ManagementFactory.getOperatingSystemMXBean();

long prevProcessCpuTime = osbean.getProcessCpuTime();

In the JDK7 docs there appears not to be any mention of them. http://docs.oracle.com/javase/7/docs/api/java/lang/management/OperatingSystemMXBean.html

enter image description here

Are there any equivalents to the jdk6 method elsewhere in the jdk7+ ?

WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
  • https://docs.oracle.com/javase/8/docs/jre/api/management/extension/com/sun/management/OperatingSystemMXBean.html#getProcessCpuTime-- – jmj Sep 16 '15 at 23:44
  • @JigarJoshi Ah so jdk8 brought back that method - and added some new ones. thx! Feel free to make this an answer. – WestCoastProjects Sep 16 '15 at 23:49
  • https://docs.oracle.com/javase/7/docs/jre/api/management/extension/com/sun/management/OperatingSystemMXBean.html#getProcessCpuTime%28%29 – jmj Sep 16 '15 at 23:50

2 Answers2

1

You are looking at wrong place in API doc, It is there in 7

https://docs.oracle.com/javase/7/docs/jre/api/management/extension/com/sun/management/OperatingSystemMXBean.html#getProcessCpuTime%28%29

jmj
  • 237,923
  • 42
  • 401
  • 438
1

It is required to cast the result:

val obs = java.lang.management.ManagementFactory
           .getOperatingSystemMXBean.asInstanceOf
          [com.sun.management.OperatingSystemMXBeanOperatingSystemMXBean]
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560