aspose file tools*
The moose likes Performance and the fly likes out of memory exception in web application! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "out of memory exception in web application!" Watch "out of memory exception in web application!" New topic
Author

out of memory exception in web application!

Neeraj Macker
Ranch Hand

Joined: Nov 10, 2004
Posts: 77
what commands can i use on a linux server to see the allocated heap and stack space and to increase it. i have a JSP web application which runs perfectly well on most machines except for one. i have to find out why this memory exhaustion is taking place.please help. i have never probed into memory issues of JVM.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Memory usage gets set on the command line - see the tooldocs for java.exe
Exactly where this gets set in your application depends on how you are starting the server. If you are starting Tomcat with startup.sh - look for the JAVA_OPTS environment setting in catalina.sh
Bill
Neeraj Macker
Ranch Hand

Joined: Nov 10, 2004
Posts: 77
Originally posted by William Brogden:
Memory usage gets set on the command line - see the tooldocs for java.exe
Exactly where this gets set in your application depends on how you are starting the server. If you are starting Tomcat with startup.sh - look for the JAVA_OPTS environment setting in catalina.sh
Bill




my catalina.sh is as follows. please tell me more about the tooldocs u have mentioned, i dont know where to look for them. i have a long main JSP which creates a number of vector objects for manipulating data. i have printed runtime.freeMemory() in the beginning of this JSP and then at the end. i get some 10 MB in the beginning. that means JVM uses only this much mem for heap. i think it is very less. how can i increase it and ideally how much should be allocated to JVM heap. Also, my vector objects shud not be long term problem because when the JSP is finished, the vector objects lose scope and hence must be GCed and the memory reclaimed.am i right?

-------------------------------------------------------------------------
i have deleted the catalina.sh for space reasons.
--------------------------------------------------------
[ December 12, 2005: Message edited by: Neeraj Macker ]
Neeraj Macker
Ranch Hand

Joined: Nov 10, 2004
Posts: 77
i made a test JSP which had nothing but this code below and i got strange results. i hope someone can justify.

runtime.freeMemory() 18 mb
runtime.totalMemory() 60 mb
runtime.maxMemory() 66 mb

what i fail to understand is that where do all these mbs between 60 and 18 get lost, without actually doing anything???
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Well, Tomcat probably *is* doing a lot behind the scenes, even if your JSP isn't.

If you are using Java 5, jconsole.exe will give you much more reliable information about memory usage, by the way.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5

JDBA_OPTS is apparently what your system uses instead of JAVA_OPTS
If you installed the documentation for your J2SE, tooldocs is a directory under docs. If you didn't install the documentation here is one online source. Look at the links for the "java" application launcher.
Bill
Neeraj Macker
Ranch Hand

Joined: Nov 10, 2004
Posts: 77
Originally posted by William Brogden:

JDBA_OPTS is apparently what your system uses instead of JAVA_OPTS
If you installed the documentation for your J2SE, tooldocs is a directory under docs. If you didn't install the documentation here is one online source. Look at the links for the "java" application launcher.
Bill


i read the tooldocs but i fail to understand how i can use it. i have a web application to monitor. what shud i mention for the name of the class to be invoked?i have JSPs to monitor..and no class with a main method.
Neeraj Macker
Ranch Hand

Joined: Nov 10, 2004
Posts: 77
Originally posted by Ilja Preuss:
Well, Tomcat probably *is* doing a lot behind the scenes, even if your JSP isn't.

If you are using Java 5, jconsole.exe will give you much more reliable information about memory usage, by the way.


i did try to run jconsole.exe but it opened up a GUI and asked for connection,i dont know what to enter there.i run the jconsole on the server itself so it has to be a local connection...but how shud i proceed, i press connect but nothing happens.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
but i fail to understand how i can use it.

From your original post, I was under the impression that you wanted to increase the memory assigned to the JVM. This is done by specifying "runtime" parameters on the command line as documented in tooldocs. It appears that your system uses the environment variable JPDA_OPTS to set runtime parameters.
In my Tomcat server I want to start with 64MB but allow use of up to 100 so my catalina.bat file has the line:

The environment variable JAVA_OPTS is used further along in the catalina.bat file to execute the Tomcat server.
Bill
Neeraj Macker
Ranch Hand

Joined: Nov 10, 2004
Posts: 77
i have already printed and seen that the total memory with JVM(runtime.totalMemory()) is 60mb. but the runtime.freeMemory() is only 20 mb. i want to know where do all these mbs get lost when there is no web application running on the server.also, i had asked how to use the options with "java" because i have to mention a class name which shud have a main metho. mine is a JSP web application.
Virag Saksena
Ranch Hand

Joined: Nov 27, 2005
Posts: 71
It seems like you want to know what objects have been created inside the heap and how they are reachable. Here is what you can do ...
Download the trial version of JAM from http://www.auptyma.com
You'll need a postgreSQL or Oracle database for use as a repository
Dump the heap before your memory usage goes up
Rename the heapdump file and dump the heap again after the heap memory usage goes up
Now you can load and compare the heaps to see what objects/instances have been created and how they are reachable.


<a href="http://www.auptyma.com" target="_blank" rel="nofollow">The Peak of Performance</a>
Neeraj Macker
Ranch Hand

Joined: Nov 10, 2004
Posts: 77
Originally posted by Virag Saksena:
It seems like you want to know what objects have been created inside the heap and how they are reachable. Here is what you can do ...
Download the trial version of JAM from http://www.auptyma.com
You'll need a postgreSQL or Oracle database for use as a repository
Dump the heap before your memory usage goes up
Rename the heapdump file and dump the heap again after the heap memory usage goes up
Now you can load and compare the heaps to see what objects/instances have been created and how they are reachable.


i am new to all these things and need detailed instructions to be able to use this package. i cudnt find much on the website. also i dont have any database available.
Virag Saksena
Ranch Hand

Joined: Nov 27, 2005
Posts: 71
Detailed instructions on dumping and analyzing heaps are in the documentation section on the web-site.

You can download postgres from www.postgresql.org and start it up (It takes about 15 minutes to get it up and running).

However as was pointed out by earlier posts, what exactly are you chasing ?
Tomcat is pure Java and it's classes will use up a certain amount of memory. As long as the memory usage is relatively stable, why worry.

If all you are looking for is the profile of Tomcat memory usage, post your version number, and I'll put up the details for memory usage.
Neeraj Macker
Ranch Hand

Joined: Nov 10, 2004
Posts: 77
my tomcat is 5.0.28

my application runs fine on the server i have. but it gave out of memory error: java heap space...on a server with similar configuration ,during testing. i am just wondering why this might have happenend.

as for tests on my server,as soon as the free memory reaches 2mb the gc takes place and the free memory again shoots up to 30 mb. i dont find any trouble here.

thats all my problem is.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: out of memory exception in web application!