package com.abc.test
import org.junit.Test
import java.util.concurrent.*
class CompletionServiceTest {
@Test
fun tesCompletionService() {
val executor = Executors.newFixedThreadPool(10)
val completionService: CompletionService<Int> = ExecutorCompletionService(executor);
completionService.submit {
Thread.sleep(1000)
100
}
completionService.submit {
Thread.sleep(2000)
200
}
completionService.submit {
Thread.sleep(5000)
1000
}
1.rangeTo(3).forEach {
val result = completionService.take()
println(result.get())
}
executor.shutdown()
executor.awaitTermination(100, TimeUnit.DAYS)
}
}
|