在少数情况下,我们的应用程序使用大约12 GB的内存.我们尝试使用jmap实用程序获取堆转储.由于应用程序使用了一些GB内存,因此会导致应用程序停止响应并导致生产中出现问题.
在我们的例子中,堆使用量在6小时内突然从2-3 GB增加到12 GB.为了找到内存使用趋势,我们尝试在重新启动应用程序后每隔一小时收集一次堆转储.但正如所说,因为使用jmap导致应用程序挂起,我们需要重新启动它,我们无法获得内存使用的趋势.
有没有办法在不挂起应用程序的情况下获取堆转储,或者是否有除jmap之外的实用程序来收集堆转储.
关于这一点的想法受到高度赞赏,因为没有得到内存使用的趋势,很难解决这个问题.
注意:我们的应用程序在CentOS中运行.
谢谢,阿伦
在我们的应用程序中,我们有线程执行特定操作.收到事件后,我们需要中断正在进行的线程.这些线程将通过调用"Thread.currentThread().isInterrupted()"来检查它们的中断状态,如果它被中断,则线程通过从run方法返回来停止.
我们现在看到的问题是这些线程可以在一个对象上等待().如果线程在对象上的wait()时被中断,则线程中断状态将被重置并抛出InterruptedException.
从1)我们有很多地方线程可以在一个对象上等待2)线程访问可以在一个对象上等待的其他对象的方法
我们决定覆盖interrupt()和isInterrupted()方法.代码看起来像
public class MyThread extends Thread {
private boolean isInterrupted = false;
@Override
public void interrupt() {
isInterrupted = true;
super.interrupt();
}
@Override
public boolean isInterrupted() {
return isInterrupted;
}
public void run() {
.........
.........
try {
object1.wait();
} catch (InterruptedException e) {
/* if interrput() is not overrided, the interrupted flag
would be reset */
}
if(Thread.currentThread().isInterrupted()) {
/* if interrupt is not overrided, isInterrupted would return
false and the thread would continue to run. …Run Code Online (Sandbox Code Playgroud)