I am trying to monitor the java heap size dynamically. Does anybody know how to get the maxmium memory used in the process of running a piece of codes? Does the Runtime.maxMemory() do the trick? Thanks
我试图动态监视Java堆大小。有人知道如何在运行一段代码的过程中获得最大内存吗? Runtime.maxMemory()可以解决这个问题吗?谢谢
9 个解决方案
#1
28
maxMemory()
returns the maximum amount of memory that java will use. So That will not get you what you want. totalMemory()
is what you are looking for though. See The docs
maxMemory()返回java将使用的最大内存量。所以那不会得到你想要的东西。 totalMemory()是你正在寻找的。请参阅文档
#2
13
There are a large number of profiler tools available that should help you with this. A popular commercial tool is YourKit, and it gets rave reviews. A free alternative is VisualVM, which I've used in the past and can provide a lot of insight.
有大量的探查器工具可以帮助您解决这个问题。一个流行的商业工具是YourKit,它得到好评如潮。一个免费的替代品是VisualVM,我过去曾使用它,可以提供很多见解。
#3
11
If you like you can visually view a lot of values profiling your app with JConsole.
如果您愿意,可以使用JConsole直观地查看分析应用程序的大量值。
http://docs.oracle.com/javase/6/docs/technotes/tools/share/jconsole.html
Start your application with:
启动您的应用程序:
-Dcom.sun.management.jmxremote
and you app will be available for select when you start /bin/jconsole.exe
当您启动/bin/jconsole.exe时,您的应用程序将可供选择
#4
11
jstat -gc <pid> <time> <amount>
jstat -gc `jps -l | grep weblogic\.Server | awk {'print $1'}` 1000 3
3 samples 1 one second see more here
3个样品1秒钟在这里看到更多
#5
6
I'd also like to add that jmap -heap <PID>
does the trick; that is assuming you're an ops guy and need to know how much heap the Java process is using. I cant tell if your question is programmatical, or operational.
我还想补充一点,jmap -heap
#6
4
There is also the java.lang.management package. Use the ManagementFactory to get an MemoryMXBean
instance. It has methods to return a heap and a non-heap memory usage snapshot.
还有java.lang.management包。使用ManagementFactory获取MemoryMXBean实例。它具有返回堆和非堆内存使用快照的方法。
#7
2
Maybe jvmtop is worth a look. It's a command-line tool which provides a live-view at several metrics, including heap size:
也许jvmtop值得一看。它是一个命令行工具,提供多个指标的实时视图,包括堆大小:
JvmTop 0.4.1 alpha amd64 8 cpus, Linux 2.6.32-27, load avg 0.12
http://code.google.com/p/jvmtop
PID MAIN-CLASS HPCUR HPMAX NHCUR NHMAX CPU GC VM USERNAME #T DL
3370 rapperSimpleApp 165m 455m 109m 176m 0.12% 0.00% S6U37 web 21
27338 WatchdogManager 11m 28m 23m 130m 0.00% 0.00% S6U37 web 31
19187 m.jvmtop.JvmTop 20m 3544m 13m 130m 0.93% 0.47% S6U37 web 20
16733 artup.Bootstrap 159m 455m 166m 304m 0.12% 0.00% S6U37 web 46
#8
1
We use app internals xpert by OpNet to monitor heap usage and leaks in realtime in our load testing environment and production. It's lightweight enough to not impact prod, so we get great data we can't get from QA. We also do profiling of methods and db calls in both environments to help us figure out what code/sql to optimize. Very cool stuff with pretty trend charts, but not free by any stretch. If you've got a lot of dollars riding on your app, it's worth the investment.
我们使用OpNet的app internals xpert在我们的负载测试环境和生产中实时监控堆使用和泄漏。它的重量足以不影响产品,因此我们获得了无法从质量保证中获得的优质数据。我们还在两个环境中对方法和db调用进行概要分析,以帮助我们确定要优化的代码/ sql。非常酷的东西与漂亮的趋势图表,但不是任何伸展*。如果您的应用程序上有很多美元,那么投资是值得的。
http://www.opnet.com/solutions/application_performance/appinternals-xpert.html
#9
0
Yet another free alternative is to use Java-monitor. Have a look at this live demo. Just click on any of the servers to see detailed graphs on heap memory, non-heap memory, file descriptors, database pools and much more.
另一种免费替代方案是使用Java监视器。看看这个现场演示。只需单击任何服务器即可查看堆内存,非堆内存,文件描述符,数据库池等详细信息。
#1
28
maxMemory()
returns the maximum amount of memory that java will use. So That will not get you what you want. totalMemory()
is what you are looking for though. See The docs
maxMemory()返回java将使用的最大内存量。所以那不会得到你想要的东西。 totalMemory()是你正在寻找的。请参阅文档
#2
13
There are a large number of profiler tools available that should help you with this. A popular commercial tool is YourKit, and it gets rave reviews. A free alternative is VisualVM, which I've used in the past and can provide a lot of insight.
有大量的探查器工具可以帮助您解决这个问题。一个流行的商业工具是YourKit,它得到好评如潮。一个免费的替代品是VisualVM,我过去曾使用它,可以提供很多见解。
#3
11
If you like you can visually view a lot of values profiling your app with JConsole.
如果您愿意,可以使用JConsole直观地查看分析应用程序的大量值。
http://docs.oracle.com/javase/6/docs/technotes/tools/share/jconsole.html
Start your application with:
启动您的应用程序:
-Dcom.sun.management.jmxremote
and you app will be available for select when you start /bin/jconsole.exe
当您启动/bin/jconsole.exe时,您的应用程序将可供选择
#4
11
jstat -gc <pid> <time> <amount>
jstat -gc `jps -l | grep weblogic\.Server | awk {'print $1'}` 1000 3
3 samples 1 one second see more here
3个样品1秒钟在这里看到更多
#5
6
I'd also like to add that jmap -heap <PID>
does the trick; that is assuming you're an ops guy and need to know how much heap the Java process is using. I cant tell if your question is programmatical, or operational.
我还想补充一点,jmap -heap
#6
4
There is also the java.lang.management package. Use the ManagementFactory to get an MemoryMXBean
instance. It has methods to return a heap and a non-heap memory usage snapshot.
还有java.lang.management包。使用ManagementFactory获取MemoryMXBean实例。它具有返回堆和非堆内存使用快照的方法。
#7
2
Maybe jvmtop is worth a look. It's a command-line tool which provides a live-view at several metrics, including heap size:
也许jvmtop值得一看。它是一个命令行工具,提供多个指标的实时视图,包括堆大小:
JvmTop 0.4.1 alpha amd64 8 cpus, Linux 2.6.32-27, load avg 0.12
http://code.google.com/p/jvmtop
PID MAIN-CLASS HPCUR HPMAX NHCUR NHMAX CPU GC VM USERNAME #T DL
3370 rapperSimpleApp 165m 455m 109m 176m 0.12% 0.00% S6U37 web 21
27338 WatchdogManager 11m 28m 23m 130m 0.00% 0.00% S6U37 web 31
19187 m.jvmtop.JvmTop 20m 3544m 13m 130m 0.93% 0.47% S6U37 web 20
16733 artup.Bootstrap 159m 455m 166m 304m 0.12% 0.00% S6U37 web 46
#8
1
We use app internals xpert by OpNet to monitor heap usage and leaks in realtime in our load testing environment and production. It's lightweight enough to not impact prod, so we get great data we can't get from QA. We also do profiling of methods and db calls in both environments to help us figure out what code/sql to optimize. Very cool stuff with pretty trend charts, but not free by any stretch. If you've got a lot of dollars riding on your app, it's worth the investment.
我们使用OpNet的app internals xpert在我们的负载测试环境和生产中实时监控堆使用和泄漏。它的重量足以不影响产品,因此我们获得了无法从质量保证中获得的优质数据。我们还在两个环境中对方法和db调用进行概要分析,以帮助我们确定要优化的代码/ sql。非常酷的东西与漂亮的趋势图表,但不是任何伸展*。如果您的应用程序上有很多美元,那么投资是值得的。
http://www.opnet.com/solutions/application_performance/appinternals-xpert.html
#9
0
Yet another free alternative is to use Java-monitor. Have a look at this live demo. Just click on any of the servers to see detailed graphs on heap memory, non-heap memory, file descriptors, database pools and much more.
另一种免费替代方案是使用Java监视器。看看这个现场演示。只需单击任何服务器即可查看堆内存,非堆内存,文件描述符,数据库池等详细信息。