Created
September 17, 2015 00:29
-
-
Save javadba/b3035c6dba84bd77389d to your computer and use it in GitHub Desktop.
getProcessingCpuLoad thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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