Skip to content

Instantly share code, notes, and snippets.

@debop
Created January 10, 2013 05:20
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 debop/4499664 to your computer and use it in GitHub Desktop.
Save debop/4499664 to your computer and use it in GitHub Desktop.
Run specified Unit in parallel mode
def runUnitAsParallel(count: Int)(block: => Unit) {
log.debug("멀티스레드 환경에서 메소드들을 [{}] 번 실행합니다.", count)
try {
val latch = new CountDownLatch(count)
val pc = collection.parallel.mutable.ParArray.iterate(0, count)(x => x)
pc.tasksupport = new ThreadPoolTaskSupport()
pc map {
_ => {
block
latch.countDown()
}
}
latch.await()
} catch {
case e: InterruptedException => log.warn("작업 중 interrupted 되었습니다.")
case e: Exception => log.error("작업 중에 예외가 발생했습니다.", e)
}
log.debug("멀티스레드 환경에서 메소드들을 [{}] 번 실행했습니다.", count)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment