[Kotlin] thread
usage
definition
```kt
/**
* Creates a thread that runs the specified [block] of code.
*
* @param start if `true`, the thread is immediately started.
* @param isDaemon if `true`, the thread is created as a daemon thread. The Java Virtual Machine exits when
* the only threads running are all daemon threads.
* @param contextClassLoader the class loader to use for loading classes and resources in this thread.
* @param name the name of the thread.
* @param priority the priority of the thread.
*/
public fun thread(start: Boolean = true,
isDaemon: Boolean = false,
contextClassLoader: ClassLoader? = null,
name: String? = null,
priority: Int = -1,
block: () -> Unit): Thread {
val thread = object : Thread() {
public override fun run() {
block()
}
}
if (isDaemon)
thread.isDaemon = true
if (priority > 0)
thread.priority = priority
if (name != null)
thread.name = name
if (contextClassLoader != null)
thread.contextClassLoader = contextClassLoader
if (start)
thread.start()
return thread
}
```
'Java Stack > Kotlin' 카테고리의 다른 글
[Kotlin] java의 static final 변수에 대응되는 것은? (0) | 2021.02.11 |
---|---|
[Kotlin] Serialization: Gson, Jackson (0) | 2020.03.19 |
[Kotlin] 제네릭 : 변성(variance), 타입 프로젝션(type projection) (1) | 2017.12.08 |
[Kotlin] 제네릭 : 타입 파라미터 소거(erasure), inline 실체화(reified) (1) | 2017.12.08 |
[Kotlin] 컬렉션과 배열 (0) | 2017.12.07 |