Created
January 10, 2013 05:20
-
-
Save debop/4499664 to your computer and use it in GitHub Desktop.
Run specified Unit in parallel mode
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
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