【问题标题】:How to enable -Dkotlinx.coroutines.debug in IntelliJ IDEA?如何在 IntelliJ IDEA 中启用 -Dkotlinx.coroutines.debug?
【发布时间】:2018-11-11 16:48:15
【问题描述】:

如何在 IntelliJ IDEA 中启用 -Dkotlinx.coroutines.debug? 我有来自coroutines documentation 的以下代码:

fun log(msg: String) = println("[${Thread.currentThread().name}] $msg")

fun main() = runBlocking<Unit> {
    val a = async {
        log("I'm computing a piece of the answer")
        6
    }
    val b = async {
        log("I'm computing another piece of the answer")
        7
    }
    log("The answer is ${a.await() * b.await()}")    
}

我试图在“运行 -> 编辑配置”中添加此选项:

但在此之后,我希望看到以下输出(如文档所说):

[main @coroutine#2] I'm computing a piece of the answer
[main @coroutine#3] I'm computing another piece of the answer
[main @coroutine#1] The answer is 42

但实际上我看到了普通的输出:

[main] I'm computing a piece of the answer
[main] I'm computing another piece of the answer
[main] The answer is 42

那么如何启用这个 JVM 选项呢?

【问题讨论】:

    标签: intellij-idea kotlin jvm coroutine kotlinx.coroutines


    【解决方案1】:

    您正在配置和运行Gradle run 目标。表示您使用此参数配置 Gradle。但 Gradle 不使用此参数来启动您的 Kotlin 示例。

    您应该运行并配置一个 Kotlin 目标。您将其视为屏幕截图左侧的第二个节点。

    或者,如果您真的想使用 Gradle,您可以将系统属性传递给 JavaVM:

    run {
        systemProperties System.properties
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-27
      • 2020-12-01
      • 2015-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-21
      相关资源
      最近更新 更多