在现有的jvm进程中执行新的java代码
我有一个 java 进程当前在 Windows shell 下运行。
负责序列化的线程之一被无限期地阻塞,因此存储在内存中的重要信息不再写入磁盘。
如果我关闭该进程,信息将会丢失。
如果我可以编写和编译一些新代码并让它在同一内存空间中执行,以便在关闭进程之前可以再次序列化所述信息,那将很方便。
该过程是使用 java -jar
命令启动的。
有了热点VM的特性,有什么办法可以实现这一点吗?
I have a java process currently running under a windows shell.
One of the threads responsible for serialisation is blocked indefinitely and as a result important information which is stored in memory is no longer being written to disk.
If I shutdown the process, the information will be lost.
It would be convenient if I could write and compile some new code and have it execute in the same memory space so that the said information could be serialised once more before I shutdown the process.
The process was started using a java -jar
command.
With the hotspot VM features, is there any way to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 附加 API 以附加到虚拟机。 这是一篇解释如何使用它的文章
这是一个代码示例:
代理在哪里你的罐子的名字。
代理 jar 包含一个 代理,它可以使用 Instrumentation API 与 JVM 进行交互。
要创建在运行时加载的代理,您可以实现如下所示的
agentmain
函数:或
Instrumentation 对象用于在运行时修改类,您可能不需要。但希望您可以将需要运行的任何代码放入 agentmain 中,然后使用 Attach API 在目标 JVM 中运行它。
祝你好运!!
You can use the Attach API to attach to a virtual machine. Here's an article that explains how to use it
Here's a code example:
Where the agent is the name of your jar.
The agent jar contains an Agent, which can interface with the JVM using the Instrumentation API.
To create an agent that gets loaded at runtime, you implement an
agentmain
function like this:or
The Instrumentation object is used to modify classes at runtime, which you probably don't need. But hopefully you can just put whatever code you need to run in agentmain and then use the attach API to run it in the target JVM.
Good luck!!
您可以尝试注册一个信号处理程序,这在 Windows 上比在其他平台上受到更多限制。
示例和说明
http://www.ibm.com/developerworks/java/library/i -signalhandling/
但要问的问题是为什么线程会被阻塞?
You might try registering a signal handler, this is more limited on Windows than on other platforms.
Examples and description
http://www.ibm.com/developerworks/java/library/i-signalhandling/
But the question to ask is why is the thread blocked?