/** * Utility method to run blocks on a dedicated background thread, used for io/database work. */ funioThread(f : () -> Unit) { IO_EXECUTOR.execute(f) }
funmain(args: Array<String>) {
println("hello from ${Thread.currentThread().name}")
thread { println("hello from ${Thread.currentThread().name}") }
ioThread { println("hello from ${Thread.currentThread().name}") } }
这一回的输出是:
1 2 3
hello from main hello from Thread-0 hello from pool-1-thread-1