Skip to content

Instantly share code, notes, and snippets.

@javadba
Created September 17, 2015 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javadba/b3035c6dba84bd77389d to your computer and use it in GitHub Desktop.
Save javadba/b3035c6dba84bd77389d to your computer and use it in GitHub Desktop.
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