在调试模式下计算实例化类的数量失败

时间:2017-08-04 14:26:54

标签: java virtual-machine kotlin allocation connection-refused

在kotlin的imgui端口工作,我有一个metrics菜单,我在其中显示分配数量

这是我写的init code

    try {
        var ac: AttachingConnector? = null
        for (x in Bootstrap.virtualMachineManager().attachingConnectors()) {
            if (x.javaClass.name.toLowerCase().indexOf("socket") != -1) {
                ac = x
                break
            }
        }
        if (ac == null) {
            throw Error("No socket attaching connector found")
        }
        val connectArgs = HashMap<String, Argument>(ac.defaultArguments())
        connectArgs["hostname"]!!.setValue("127.0.0.1")
        connectArgs["port"]!!.setValue(Integer.toString(3001))
        connectArgs["timeout"]!!.setValue("3000")
        vm = ac.attach(connectArgs)
    } catch (error: Exception) {
        System.err.println("Couldn't retrieve the number of allocations, $error")
    }

这些是我传递的参数&#39; VM选项&#39;

-Xdebug -Xrunjdwp:transport=dt_socket,address=3001,server=y,suspend=n

每当我正常运行它,它都有效。但是,如果我在调试模式下运行它,它不会,返回以下错误:

  

java.net.ConnectException:连接被拒绝:连接

我无法找到解决方案,目前我只是显示-1来表示错误

有没有人有解决方案/解释?

规格:

  • Kotlin 1.2-m1
  • Idea 2017.2.1

1 个答案:

答案 0 :(得分:0)

我想问题是你尝试使用与程序使用的调试器相同的端口。尝试为调试器使用不同的端口。