美文网首页
Kotlin协程

Kotlin协程

作者: 自然V简单 | 来源:发表于2020-02-04 10:31 被阅读0次

今天看到Kotlin的协程,跑下面的demo,不对比,还真是不知道差距这么大,以前只是从文字上看说是是性能高,现在通过这样的对比,才算是有个更具体的了解。

fun main(args: Array<String>) {

    val c = AtomicLong()

println(LocalDateTime.now())

for (iin 1..1_000_000_0L)

thread (start = true){

            c.addAndGet(i)

}

println(LocalDateTime.now())

println(c.get())

}

2020-02-04T09:39:39.522

2020-02-04T09:46:54.356

fun main(args: Array<String>) {

val c = AtomicLong()

println(LocalDateTime.now())

for (iin 1..1_000_000_0L)

GlobalScope.launch {

            c.addAndGet(i)

}

println(LocalDateTime.now())

println(c.get())

}

2020-02-04T10:24:07.622

2020-02-04T10:24:34.855

相关文章

网友评论

      本文标题:Kotlin协程

      本文链接:https://www.haomeiwen.com/subject/emzlxhtx.html