1

I have a java application. The issue now I take a heap using the jmap and I also got this codes running in my application.Both are giving me different values. The runtime is showing out of 256mb which is what I have assigned as initial and maximum memory? I want to detect is there any memory leakage but the runtime is fluctuating and whereas the one from heap is keep increasing in small amount? Any help on this?

long memory = runtime.totalMemory() - runtime.freeMemory();
System.out.println("\n\nUsed memory is bytes: " + memory);

//Print the jvm heap size.
long heapSize = runtime.totalMemory();
System.out.println("\n\nHeap Size = " + heapSize);

int mb = 1024*1024;
System.out.println("##### Heap utilization statistics [MB] #####");

//Print used memory
System.out.println("Used Memory:" + (runtime.totalMemory() - runtime.freeMemory()) / mb);

//Print free memory
System.out.println("Free Memory:" + runtime.freeMemory() / mb);

//Print total available memory
System.out.println("Total Memory:" + runtime.totalMemory() / mb);

//Print Maximum available memory
System.out.println("Max Memory:" + runtime.maxMemory() / mb);
ksugiarto
  • 940
  • 1
  • 17
  • 40
user2711681
  • 285
  • 7
  • 16

2 Answers2

1

I recommend using Visual VM to watch memory usage etc.

dkatzel
  • 31,188
  • 3
  • 63
  • 67
  • I have problem using it tried many ways to link to my remote application but it failed so that that is why I revert to all this mechanism ? – user2711681 Aug 27 '13 at 02:39
  • Have you looked at the Visual VM tutorial on connecting to remote apps? http://visualvm.java.net/applications_remote.html – dkatzel Aug 27 '13 at 14:03
0

Alternativly you can try Netbeans profiler. You can profile your web/standalone applications using netbeans profiler.

We are uning netbeans profiler to profiling in our applications. Nice tool for profiling the java applications.

Check it out.

https://profiler.netbeans.org/

http://wiki.netbeans.org/FaqProfilerAttachRemoteServer

Prabhakaran Ramaswamy
  • 25,706
  • 10
  • 57
  • 64
  • Is it possible for me not to mess with allow any permission stuff cause of security of the server. Cant I use the jmap instance to do a profiling? What is your comment on that ? – user2711681 Aug 27 '13 at 02:55
  • You need the permission to execute sh file on server. So only you can use net-beans pro-filer. And need to open one port to profile binding through netbeans IDE. – Prabhakaran Ramaswamy Aug 27 '13 at 03:00
  • What else must I install on it? How to bind the port for the profiling is it similar to Visual VM ? – user2711681 Aug 27 '13 at 03:16
  • I am not running any of the servers stated here http://wiki.netbeans.org/FaqProfilerAttachRemoteServer mine is just a socket application. – user2711681 Aug 27 '13 at 03:26
  • Nothing else need to install. I never tried VisualVM. Using netbeans profiler i can profilie memory, cpu usage , delay to excute the methods and much more... http://stackoverflow.com/questions/948549/open-source-java-profilers – Prabhakaran Ramaswamy Aug 27 '13 at 03:26
  • install net-beans and click the profiler. Decide What you are going to profile CPU/memory and select remote/local. It will show the instructions you need to copy that one and follow that. – Prabhakaran Ramaswamy Aug 27 '13 at 03:33
  • Ok thank let me do the downloading complete first then I will try and get back to you. – user2711681 Aug 27 '13 at 03:45
  • I am on centos platform so I have into the profile. I have clicked on the create a remote profiling it bring into a temp folder? Quite lost here – user2711681 Aug 27 '13 at 05:03
  • I follow the first link which says this instruction Choose Profile -> Profile Main Project ( Profile Main Project ) from the main menu. mine is not active and not able to click on it. Only active is the Attach Profiler – user2711681 Aug 27 '13 at 07:30