To initialize the object, Thread
you simply call the constructor:
val t = Thread()
Then you can also pass an optional Runnable
with a lambda expression (SAM conversion) as follows:
Thread {
Thread.sleep(1000)
println("test")
}
A more explicit version conveys an anonymous implementation Runnable
as follows:
Thread(Runnable {
Thread.sleep(1000)
println("test")
})
Note that the previously shown examples only create an instance Thread
but do not actually start it. For this you need to explicitly call start()
.
, : thread
, :
public fun thread(start: Boolean = true, isDaemon: Boolean = false, contextClassLoader: ClassLoader? = null, name: String? = null, priority: Int = -1, block: () -> Unit): Thread {
:
thread(start = true) {
Thread.sleep(1000)
println("test")
}
, , , . , true
start
.