aspose file tools*
The moose likes Tomcat and the fly likes java.lang.OutOfMemory Exception in Apache Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "java.lang.OutOfMemory Exception in Apache" Watch "java.lang.OutOfMemory Exception in Apache" New topic
Author

java.lang.OutOfMemory Exception in Apache

Rishi Tyagi
Ranch Hand

Joined: Feb 14, 2002
Posts: 100
Hi All,
I am facing one severe problem with Apache tomcat on linux.

Jdk Version : jdk1.4.1
Tomcat Apache : 3.3.1

No problem is whenever i put the load on some application which interacts with database servers goes down and gives the following error message.
//***********************
Jul 27, 2004 11:01:50 AM org.apache.tomcat.util.threads.ThreadPool$ControlRunnab
le run
SEVERE: Caught exception (java.lang.OutOfMemoryError) executing org.apache.tomca
t.util.net.TcpWorkerThread@59c8b5, terminating thread
java.lang.OutOfMemoryError
java.lang.OutOfMemoryError
//***********************

I would like to ask why this error occurs and what can we do for preventing our system from going down due to this error.

Thanks in advance for the help extended

Regards,
Rishi
Rishi Tyagi
Ranch Hand

Joined: Feb 14, 2002
Posts: 100
What happened, Out of so many java guru's nobody is able to solve my problems.

If anybody has ever faced the same problem then pl suggest a solution for the same.

Thanks in advance

Regards,
Rishi Tyagi
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Well, friend, it is YOUR problem. Normally Java programs hit this error when the design is sloppy about managing objects, or you just have not allocated enough memory for normal operation.
Since a database is involved one is naturally lead to ask how you are managing database connections - are you using one of the connection pool toolkits?
Also, lets have more details about the load - does this happen with the very first query, the 100th? what?
If a review of your code reveals that you are managing connections, etc correctly, the next step could be to use one of the memory monitoring tools like jProbe.
You might also look at earlier posts in this forum asking about the same problem.
Bill
[ August 09, 2004: Message edited by: William Brogden ]
Rishi Tyagi
Ranch Hand

Joined: Feb 14, 2002
Posts: 100
William Brogden ,
First of all i would like to say thanks for the answer.

Now let us come on the topic.
1- Connection Pool
Yes i am using one third party api rpDBPool.jar for implementation of connection pooling.

2- When does this problem occurs:
infact when i restart the tomcat it runs ok for some time. if there is less load on the applications then too it works fine. But problem occurs when load increases. You can say it happens with the 100th request.

One silly question i would like to ask that is : Is there any relationship between the max number of connections defined in the connection pool and the max number of processes in tomcat?

Infact when i increase the value of max processes in the <Tomcat Home Dir>/conf/server.xml file then the error occurs very frequently but when i put this value to 100 then frequency of the error decreases.
Some more questions i would like to ask about jakarta-tomcat server
1- Is there any possibility of cloning the jakarta-tomcat server to handle the load if it increases to the limit of one instance.
2- How can we increase the memory assigned to jvm running tomcat, i.e where can we use the -Xmx256m option in the configuration files.
3- Is there any good online document available for this server, which can help to study out this server deeply.
Regards,
Rishi Tyagi
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
I would proceed in this order.
1&2. Make sure that connections from the connection pool are properly closed and disposed of. Your observation that it takes about 100 queries to hit the error suggests that connections are not being properly recycled. Also be sure that all JDBC objects are properly closed/released/whatever.

3. Provide for logging (or just System.out.print) memory use after each request. See the java.lang.Runtime methods.

The number of Threads available in Tomcat to process requests is set in server.xml. The configuration of the connection pool probably is done with some sort of initialization parameters - see the rpDBPool docs. Of course it makes no sense to have more connections than request threads.

There is nothing to be gained by multiple instances of Tomcat on the same machine, if you give Tomcat enough memory. If you have a multiprocessor machine, it will use both automatically.

As I recall, you can set the command line parameters such as memory as the "JAVA_OPTS" environment value or in the catalina.bat file.

The documentation that comes with your tomcat installation is the most coherent online docs I have found. There is a new edition of "Professional Apache Tomcat" - I found the previous edition to be very useful.
Bill
Rishi Tyagi
Ranch Hand

Joined: Feb 14, 2002
Posts: 100
Thanks William Brogden,

Infact increasing the memory in java_opts variable helps but not much. Still there is one problem:

After running for some time timcat hangs out, although it is not giving any error like out of memory or any other.
But it stops responding to the request.

What is the reason behind it and what is the solution for the same. Can you help on this .

Regards,
Rishi Tyagi
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
On Windows, I would look at the Task Manager to see what the CPU usage of the Tomcat process is - I assume you have a similar tool on Linux.
If the usage is high, it would seem your application is stuck in a loop somewhere. If low to zero, it is probably waiting on the database server.
Can you get any monitoring information from the database server - such as how many connections are open?
How much logging have you implemented in Tomcat?
Bill
Rishi Tyagi
Ranch Hand

Joined: Feb 14, 2002
Posts: 100
Thanks William Brogden for your support.

Problem seems to be sorted out. Infact some of the jsp applications were creating problems.

Regards,
Rishi tyagi
 
 
subject: java.lang.OutOfMemory Exception in Apache