Accessing VirtualMachine and HotspotVirtualMachine classes from JDK1.5
How can I use sun.tools.attach.HotSpotVirtualMachine
an开发者_如何学Cd com.sun.tools.attach.VirtualMachine
in JDK1.5?
These classes were introduced in Java 6 (Mustang) so the short answer is that you cannot use them in Java 5 (JDK 1.5).
A slightly longer answer is that you might in theory be able to backport these classes to Java 5. However, this would entail making changes to the source code base for the Java 5 virtual machine, and Sun / Oracle have never published that. What is more, the back port wouldn't be Java 5 any more.
In response to @Peter Lawrey's answer, it used to be the case that accessing sun.*
classes was considered a big no-no. However, more recently Sun has been creating new APIs that are intended for public use (at least in certain contexts). The "Attach" API is one such example.
The Attach API is not part of the standard Java SE class library, so using it is potentially going to make your application (or Java tool) platform specific. And there is undoubtedly some risk in using an API that lets you interact with the JVM at this level. But certainly Sun published the API with the intention that people should be able use it ... where appropriate.
You cannot use sun.* classes safely in any version of Java. These are for internal use only and can change/disappear between updates of Java.
You can try it by attaching the tools.jar library at your own risk. http://www.docjar.com/docs/api/sun/tools/attach/HotSpotVirtualMachine.html
精彩评论