100% CPU usage when ending a test with HawtDispatch

60 views
Skip to first unread message

Jon Brisbin

unread,
Oct 3, 2011, 1:35:49 PM10/3/11
to hawtdi...@googlegroups.com
I'm using a simple test class in my sbt-powered project. When I run this class with "test-run HawtDispatchTest", the test runs fine, but when the test is over, my CPU usage spikes at 100% like it would if I was in a tight infinite loop (it's the system CPU at 100%, not the user CPU, so it's at a very low level). Anyone seen this behaviour with sbt? Is there a cleanup/shutdown method I'm supposed to be calling I'm not? I couldn't find one...

The full code of the test:

object HawtDispatchTest {

  def main(args: Array[String]) {
    val latch = new CountDownLatch(100)
    val test = Dispatch.createQueue("test")
    for (i <- 0 until 100) {
      val r = new Runnable {
        def run() {
          println("run job " + i.toString + " on thread: " + Thread.currentThread().toString)
          latch.countDown()
        }
      }
      test.execute(r)
      println("submitted job: " + i.toString)
    }
    latch.await()

    println("finished...exiting")
  }

}


Thanks!

Jon Brisbin
http//jbrisbin.com

Hiram Chirino

unread,
Oct 3, 2011, 3:45:08 PM10/3/11
to hawtdi...@googlegroups.com
I just tried that code sample out in my IDE and it worked fine. What
OS/JDK are you using? Could you push the example sbt project to
github? That way I could try it out?

BTW, if you `import org.fusesource.hawtdispatch._` then you can use
the scala enriched interfaces for DispatchQueue so you can reduce your
example down to:

import org.fusesource.hawtdispatch._
import java.util.concurrent.CountDownLatch

object HawtDispatchTest {

def main(args: Array[String]) {
val latch = new CountDownLatch(100)
val test = Dispatch.createQueue("test")
for (i <- 0 until 100) {

test {


println("run job " + i.toString + " on thread: " +
Thread.currentThread().toString)
latch.countDown()
}

println("submitted job: " + i.toString)
}
latch.await()
println("finished...exiting")
}
}


Regards,
Hiram

FuseSource
Web: http://fusesource.com/

Jon Brisbin

unread,
Oct 3, 2011, 3:46:38 PM10/3/11
to hawtdi...@googlegroups.com
I had continuations enabled in my sbt Project class. That's what was causing the CPU spike. I took that option out and it quit doing that. I don't know why it was triggered, though.


Thanks!

Jon Brisbin
http//jbrisbin.com


Reply all
Reply to author
Forward
0 new messages