0

I think I may have a memory leak in a servlet application running in production on jetty 8.1.7.

  1. Is there a way of seeing how much heap memory is actually being used at an instance of time, not the max memory allocated with -Xmx, but the actual amount of memory being used.
  2. Can I force a garbage collection to occur for an application running within jetty
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
  • Possible duplicate of [How to force garbage collection in Java?](http://stackoverflow.com/questions/1481178/how-to-force-garbage-collection-in-java) – Raedwald Mar 31 '16 at 16:05

4 Answers4

2

yes, both are easily achievable using: VisualVM (see: http://docs.oracle.com/javase/6/docs/technotes/guides/visualvm/monitor_tab.html) This one is shipped with Oracle JDK by default (=> no extra installation required)

However for the memory leak detection, I'd suggest to do memory dump and analyze it later with eclipse MAT ( http://www.eclipse.org/mat/ ) as it has quite nice UI visualizing java memory dumps.

EDIT:

For the ssh only access, yes you can use the mentioned two tools. However you need to run them on the machine with running window manager and remotely connect over ssh to the other machine (you need to have java on both of these machines):

  • For visualVM: you need to have VisualVM running on one maching and via the ssh connect to remote one, see: VisualVM over ssh
  • and for the memory dump: use jmap (for sample usage see: http://kadirsert.blogspot.de/2012/01/…) afterwards download the dump file and load if locally to eclipse MAT
Community
  • 1
  • 1
Peter Butkovic
  • 11,143
  • 10
  • 57
  • 81
0

You can call System.gc(). That will typically perform a full GC ... but this facility can be disabled. (There is a JVM option to do this with HotSpot JVMs.)

However, if your problem is a memory leak, running the GC won't help. In fact, it is likely to make your server even slower than it currently is.

You can also monitor the memory usage (in a variety of ways - see other Answers) but that only gives you evidence that a memory leak might leak.

What you really need to do is find and fix the cause of the memory leak.

Reference:

Community
  • 1
  • 1
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

enable jmx and connect up to it using jconsole

http://wiki.eclipse.org/Jetty/Tutorial/JMX

jesse mcconnell
  • 7,102
  • 1
  • 22
  • 33
0

You can use jvisualvm.exe which is under the %JAVA_HOME%\bin folder. By using this application you can monitor memory usage and can force gc.

bhdrkn
  • 6,244
  • 5
  • 35
  • 42