473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Java out of memory exception

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
10 19369
horace1
1,510 Expert 1GB
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
r035198x
13,262 8TB
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
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
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
horace1
1,510 Expert 1GB
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
r035198x
13,262 8TB
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
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
r035198x
13,262 8TB
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
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
Mohanj
2
Please check the below url

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

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

Similar topics

2
by: Patrick | last post by:
I'm using Jakarta-POI to create a huge Excel spreadsheet. I get the error below when the spreadsheet grows to a large size. It seems to have something to do with the number of "cell" objects that I...
3
by: Gert Schumann | last post by:
I'm operating on sun OS 5.6 I ping a host every 10 seconds to get knowlegde wheather it is running or not. After about one and a half hour I get this Exception: java.io.IOException: Too many open...
133
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
236
by: Andrew Rawnsley | last post by:
Anyone out there using beta 2 in production situations? Comments on stability? I am rolling out a project in the next 4 weeks, and really don't want to go though an upgrade soon after its released...
15
by: Paul Morrison | last post by:
Hi all, I need to come up with some differences between arrays in Java and C, I have searched Google and so far all I have found is the following: Arrays in Java are reference types with...
3
by: Sai Kit Tong | last post by:
I posted for help on legacy code interface 2 days ago. Probably I didn't make it clear in my original mail. I got a couple of answers but none of them address my issues directly (See attached...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
2
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.