AttachNotSupportedException

AttachNotSupportedException

我在linux(ubuntu 64位)上运行jmockit测试时得到AttachNotSupportedException。 Java版本是1.7.0_51。该JDK来自Oracle。使用ant运行测试(可能不相关)

请参阅堆栈跟踪。

[junit]
[junit] java.lang.RuntimeException: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
[junit]     at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:89)
[junit]     at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:54)
[junit]     at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:21)
[junit]     at mockit.internal.startup.Startup.initializeIfNeeded(Startup.java:136)
[junit]     at mockit.internal.startup.Startup.initializeIfPossible(Startup.java:169)
[junit]     at junit.framework.TestResult.<clinit>(TestResult.java:15)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:356)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1165)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:1016)
[junit] Caused by: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
[junit]     at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:106)
[junit]     at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:79)
[junit]     ... 8 more
[junit] Exception in thread "main" java.lang.ExceptionInInitializerError
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:356)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1165)
[junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:1016)
[junit] Caused by: java.lang.RuntimeException: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
[junit]     at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:89)
[junit]     at mockit.internal.startup.JDK6AgentLoader.loadAgent(JDK6AgentLoader.java:54)
[junit]     at mockit.internal.startup.AgentInitialization.initializeAccordingToJDKVersion(AgentInitialization.java:21)
[junit]     at mockit.internal.startup.Startup.initializeIfNeeded(Startup.java:136)
[junit]     at mockit.internal.startup.Startup.initializeIfPossible(Startup.java:169)
[junit]     at junit.framework.TestResult.<clinit>(TestResult.java:15)
[junit]     ... 3 more
[junit] Caused by: com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
[junit]     at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:106)
[junit]     at mockit.internal.startup.JDK6AgentLoader.getVirtualMachineImplementationFromEmbeddedOnes(JDK6AgentLoader.java:79)
[junit]     ... 8 more
[junit] Running chs.caf.cap

它似乎与AttachNotSupportedException while running jMockit tests on IBM JRE有关。但是,这是在IBM jre上。

最佳答案

我的回答会有些不相关,但是在尝试使用jcmd转储线程时遇到了同样的问题。即使我在用户下运行jcmd,也收到相同的错误消息。
您需要在下以与Java进程相同的用户身份来运行jcmd <pid> Thread.print,否则您的连接将被删除。 Java不在乎您是否是
所以基本上:

sudo -u <java_process_user> jcmd <pid> Thread.print

关于linux - com.sun.tools.attach.AttachNotSupportedException : Unable to open socket file: target process not responding or HotSpot VM not loaded,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25438983/

10-10 08:06