By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,032 Members | 825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,032 IT Pros & Developers. It's quick & easy.

Java out of memory exception

P: 35
Hi all ,
I am new to this . This is my first post . I really need some help from you all members of this forum.
My situation is something like this .
I am communicating with 2 system .Both the systems are in LAN . In the first system (Windows xp) my java application and database (MYSQL 5.0) is running.
My second system is my linux machine which has an applcation running which sends some xyz information for every packet which it receive to my java application.It is configurable for example if I give tcp packets then it will send information only when TCP packet is recived .Similarly If I give ICMP packets then it will send information only when ICMP packet is recived ... .

What i am doing is i am reading the information from the socket and inserting into some table in the database. Some time when the traffic over network is high I am getting around 10000 messages per second.
So what i m doing is i am adding the message as an string object to a vector. And i have a thread running which for every 2 seconds read that vector and perform a bulk insertion to the database with the values in that vector and then empty the vector.
This logic is working properly but sometimes when traffic is very high then I get runtime exception ie java out of memory exception.
How to solve this problem please can anyone help me out.

Thank you for your response
Jan 9 '07 #1
Share this Question
Share on Google+
10 Replies


Expert 100+
P: 1,510
you can increase the JVM heap size, see discussion
http://forum.java.sun.com/thread.jspa?threadID=490356&tstart=0

but the problem may still occure

could you use a double buffer? be filling one buffer which another thread is writing the other buffer - you can then test to see if first buffer is full before the second is writen - if so you can think about solving that problem, e.g. may need faster machine, faster disk, bigger disk cache?
Jan 9 '07 #2

10K+
P: 13,264
Hi all ,
I am new to this . This is my first post . I really need some help from you all members of this forum.
My situation is something like this .
I am communicating with 2 system .Both the systems are in LAN . In the first system (Windows xp) my java application and database (MYSQL 5.0) is running.
My second system is my linux machine which has an applcation running which sends some xyz information for every packet which it receive to my java application.It is configurable for example if I give tcp packets then it will send information only when TCP packet is recived .Similarly If I give ICMP packets then it will send information only when ICMP packet is recived ... .

What i am doing is i am reading the information from the socket and inserting into some table in the database. Some time when the traffic over network is high I am getting around 10000 messages per second.
So what i m doing is i am adding the message as an string object to a vector. And i have a thread running which for every 2 seconds read that vector and perform a bulk insertion to the database with the values in that vector and then empty the vector.
This logic is working properly but sometimes when traffic is very high then I get runtime exception ie java out of memory exception.
How to solve this problem please can anyone help me out.

Thank you for your response
If you can post the code for storing in vector and reading the vector and inserting to database perhaps there could be ways of optimizing it.
Jan 9 '07 #3

P: 35
If you can post the code for storing in vector and reading the vector and inserting to database perhaps there could be ways of optimizing it.
Hi r035198x ,

Thanks for your quick response
But I cant really diverge the whole code its aganist my company policy
but a the logic is something like this

I have a static vector for example in class A and i have declared as below

static Vector dataVector= new Vector();

In one thread (ReadSocket Thread)i am filling this vector

void run (){

// performing operation for reading the infromation from the socket
and storing in a string

String message = // store the message in string object
A.dataVector.add(message);

// this thread will always be running with the highest priority and i
have set this as dameon thread
}


Another thread is also (WriteToDatabase Thread) in which i read the vector


void run(){
int n = A.dataVector.size();
if(! A.dataVector.isEmpty()){
PreparedStatement db = _con.prepareStatement ( "INSERT
INTO messageTable (aaa,bbb,ccc,ddd,mess) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?);");

while (n>0){
String message = (String) A.dataVector..elementAt(0);
// setting the parameter ...
db.setInt(..)
db.setInt(..)
db.setString(message)
// in that table there are nearly 20 feilds ...
db.addbatch();
n--;
}
da.executeBatch();

}

}


This is simple logic which i am using and there are some other threads running in the background also..
Jan 9 '07 #4

P: 35
you can increase the JVM heap size, see discussion
http://forum.java.sun.com/thread.jspa?threadID=490356&tstart=0

but the problem may still occure

could you use a double buffer? be filling one buffer which another thread is writing the other buffer - you can then test to see if first buffer is full before the second is writen - if so you can think about solving that problem, e.g. may need faster machine, faster disk, bigger disk cache?

Hi horace1
Thanks for your quick response.
My machine is with 1 gb RAM .
I saw that link which you have given.But there is no solution given .
If you have any please suggest me how to increase the JVM heap size

Thank you
prakash
Jan 9 '07 #5

Expert 100+
P: 1,510
Hi horace1
Thanks for your quick response.
My machine is with 1 gb RAM .
I saw that link which you have given.But there is no solution given .
If you have any please suggest me how to increase the JVM heap size

Thank you
prakash
have a look at
http://java.sun.com/docs/hotspot/ism.html
http://www.onjava.com/pub/a/onjava/2001/08/22/optimization.html
Jan 9 '07 #6

10K+
P: 13,264
Hi horace1
Thanks for your quick response.
My machine is with 1 gb RAM .
I saw that link which you have given.But there is no solution given .
If you have any please suggest me how to increase the JVM heap size

Thank you
prakash
It is not neccessary to visit another forum for this.
IIncreasing the available JVM heap size is simply done with the -Xmx parameter to the JVM. Type java -X to get help on using the other options
Jan 9 '07 #7

P: 35
It is not neccessary to visit another forum for this.
IIncreasing the available JVM heap size is simply done with the -Xmx parameter to the JVM. Type java -X to get help on using the other options

Thank you .
But I have another problem .. I am running my application from eclipse
and I have to make an exe file with installsheild software and give it to a customer..

In that exe file i compress my JVM also .
So how to handle this situation .. Is there any way to increase JVM heap size
at runtime
Jan 12 '07 #8

10K+
P: 13,264
Thank you .
But I have another problem .. I am running my application from eclipse
and I have to make an exe file with installsheild software and give it to a customer..

In that exe file i compress my JVM also .
So how to handle this situation .. Is there any way to increase JVM heap size
at runtime
You may need to create a platform-dependant native wrapper that launches a .exe which launches the JVM with the required heap size options.

Another method is to run the program using shell script or a batch but may not suit your requirements.
Jan 12 '07 #9

P: 1
Hi all ,
I am new to this . This is my first post . I really need some help from you all members of this forum.
My situation is something like this .
I am communicating with 2 system .Both the systems are in LAN . In the first system (Windows xp) my java application and database (MYSQL 5.0) is running.
My second system is my linux machine which has an applcation running which sends some xyz information for every packet which it receive to my java application.It is configurable for example if I give tcp packets then it will send information only when TCP packet is recived .Similarly If I give ICMP packets then it will send information only when ICMP packet is recived ... .

What i am doing is i am reading the information from the socket and inserting into some table in the database. Some time when the traffic over network is high I am getting around 10000 messages per second.
So what i m doing is i am adding the message as an string object to a vector. And i have a thread running which for every 2 seconds read that vector and perform a bulk insertion to the database with the values in that vector and then empty the vector.
This logic is working properly but sometimes when traffic is very high then I get runtime exception ie java out of memory exception.
How to solve this problem please can anyone help me out.

Thank you for your response
hi ,
i read your problem, i suggest to you try some thing as follows :

1) try to sleeping of thread.
2) check whether every thread not created new connection. because when u create connection 4 objects they are created in a heap.
3) check once the thread finished resources must be free.
4)read some advanced JDBC featured like datasouce.
5)think about pooledConnection.

please let me know when your problem soved.
best of luck
bye
Feb 18 '08 #10

P: 2
Please check the below url

http://techieidea.blogspot.com/searc...&max-results=5
Nov 13 '09 #11

Post your reply

Sign in to post your reply or Sign up for a free account.