Solved

memory usage in a java program running on linux

Posted on 2006-07-17
6
221 Views
Last Modified: 2012-05-05
I have a very simple Java program running in linux:

public class test
{

    public test()
    {}

    public static void main(String[] args)
    {
      test t1 = new test();
      t1.begin();
    }

    public void begin()
    {
       while(true)
       {
           try
           {
                System.out.println("one iteration");
                Thread.sleep(5*60*1000);
           }
           catch(Exception ex)
           { ex.printStackTrace(); }
        }
     }
}

What is the best way to find the memory used by this process in linux.

I am using the jvm property (-mx3000000) to cap the maximum memory usage to 3MB. which means that if the jvm uses more than 3MB it would throw outOfMemoryError.
I have tried to monitor this process using the JConsole and the memory does not exceed the 3MB limit.

I am aware of two commands : top and pmap

if I use the top command it shows that the process using 23 MB

and pmap command (which can be used to view the private bytes ) shows that the process is using 123 MB.
(this is just the writable/private bytes)

I am new to linux. Can anyone please explain that if the jvm property forces the process to terminate  if it uses more than the assigned memory (max memory), where do I find the explanation for the remaining memory usage.





0
Comment
Question by:rnicholus
6 Comments
 
LVL 92

Accepted Solution

by:
objects earned 168 total points
Comment Utility
you're only limiting the amount of heap available in the jvm, yoiu are not limiting the amount of memory the vm takes from the OS
0
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 166 total points
Comment Utility
0
 
LVL 30

Assisted Solution

by:mayankeagle
mayankeagle earned 166 total points
Comment Utility
0
 

Author Comment

by:rnicholus
Comment Utility
Thank you. I will try to use the memory profiler.

freeMemory() and totalMemory() methods from the Runtime class also account for the heap and not the total memory
used by the process.


0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now