Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
getProcessingCpuLoad thread
val latch = new java.util.concurrent.CountDownLatch(1)
val t = new Thread() {
override def run() = {
var x = 1.0
val startt = System.currentTimeMillis
for (i <- 1 to lnLoops) {
x = (x * math.pow(i, 1.2) * i) /
(math.pow(x, 1.5) * math.sqrt(i) * math.max(math.abs(math.cos(x)), 0.1) * math.pow(i, 1.21))
}
println(s"X=$x duration=${System.currentTimeMillis-startt}")
latch.countDown
}}
t.start
val mb = java.lang.management.ManagementFactory.getOperatingSystemMXBean
.asInstanceOf[com.sun.management.OperatingSystemMXBean]
while (latch.getCount > 0) {
Thread.sleep(1000)
println(s"CpuLoad= ${mb.getProcessCpuLoad}")
}
println("latch down detected")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.