473,379 Members | 1,355 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,379 software developers and data experts.

derby - java.lang.OutOfMemoryError Java heap space

im trying to iterate through a large database (over 5000 entries), and printing out the entries
using this code:
Expand|Select|Wrap|Line Numbers
  1. String sql = "SELECT "+column+ " ,clickurl from " + tableName;
  2. stmt = conn.prepareStatement(sql);
  3. ResultSet results=stmt.executeQuery();
  4.  
  5. while(results.next()){
  6.  
  7. String clickurl = results.getString(2);
  8. System.out.println(" Test - " + clickurl);
  9. }
  10.  
but after the 4000. entry java runs out of memory.

i dont know if i understand the system correctly, but the results are stored in the a ResultSet variable already, and iterating through it shouldn't require more memory.

i can't figure out what the problem is.
Jul 16 '08 #1
8 7411
Atli
5,058 Expert 4TB
Hi.

Seeing as this is more of a Java problem than a MySQL problem, I've moved it over to the Java Forum.
Jul 16 '08 #2
Nepomuk
3,112 Expert 2GB
im trying to iterate through a large database (over 5000 entries), and printing out the entries
using this code:
Expand|Select|Wrap|Line Numbers
  1. String sql = "SELECT "+column+ " ,clickurl from " + tableName;
  2. stmt = conn.prepareStatement(sql);
  3. ResultSet results=stmt.executeQuery();
  4.  
  5. while(results.next()){
  6.  
  7. String clickurl = results.getString(2);
  8. System.out.println(" Test - " + clickurl);
  9. }
  10.  
but after the 4000. entry java runs out of memory.
It will probably help, to put
Expand|Select|Wrap|Line Numbers
  1. String clickurl = "";
before the loop and just
Expand|Select|Wrap|Line Numbers
  1. clickurl = results.getString(2);
in it. That way, you don't create a new string every time the loop is called, instead it's overwritten. Otherwise, the garbage collector would have to clean it up and it doesn't seem to be doing that in time.
i dont know if i understand the system correctly, but the results are stored in the a ResultSet variable already, and iterating through it shouldn't require more memory.
I think you're wrong with that. As I understand it, you're creating a new copy of a string every time the loop is called. It's like
Expand|Select|Wrap|Line Numbers
  1. public class CompareStrings {
  2.     public static void main(String[] args) {
  3.         StringWrapper sw = new StringWrapper();
  4.         String hi = sw.getWord();
  5.         System.out.println(hi == sw.hello);
  6.     }
  7. }
  8.  
  9. class StringWrapper {
  10.     public String hello = "Hello";
  11.     public String getWord() {return new String(hello);}
  12. }
Check it, it will return false. That's why your program runs out of memory.

Of course, you could just do this:
Expand|Select|Wrap|Line Numbers
  1. while(results.next()){
  2.  
  3. System.out.println(" Test - " + results.getString(2));
  4. }
That won't work of course, if you need the String clickurl somewhere else.

Greetings,
Nepomuk
Jul 16 '08 #3
JosAH
11,448 Expert 8TB
It will probably help, to put
Expand|Select|Wrap|Line Numbers
  1. String clickurl = "";
before the loop and just
Expand|Select|Wrap|Line Numbers
  1. clickurl = results.getString(2);
in it. That way, you don't create a new string every time the loop is called, instead it's overwritten. Otherwise, the garbage collector would have to clean it up and it doesn't seem to be doing that in time.
The gc always runs when it is desparately needed; one local String doesn't
increase the consumed memory much; the gc will clean it up. I use Derby
myself and just conducted a small test: 100,000 rows without any problems
so I guess the problem is somewhere else ...

kind regards,

Jos
Jul 16 '08 #4
JosAH
11,448 Expert 8TB
ps. probably your cache size is too small; e.g. set this property:

Expand|Select|Wrap|Line Numbers
  1. derby.storage.pageCacheSize    =    4M
  2.  
kind regards,

Jos
Jul 16 '08 #5
hi,
thanks for the suggestions. i tried to run it without creating a string, but it still runs out of memory, although slightly later.
where can i set derby.storage.pageCacheSize?

thanks
Jul 16 '08 #6
JosAH
11,448 Expert 8TB
where can i set derby.storage.pageCacheSize?
Put it in your System.properties before you start Derby or use a command line
parameter -Dderby.storage.pageCacheSize=4M

kind regards,

Jos
Jul 16 '08 #7
Hi Jos,

thanks for the reply, I added these lines (-J-Dderby.storage.pageSize=8m -J-Dderby.storage.pageCacheSize=8m) to netbeans.conf, it shows up as an argument, but doesnt seem to effect the application. it still runs out of memory, i was trying to play with the numbers, but nothing happened.

(i have 4gb memory assigned 512/512 heap/non heap memory, that should be enough i guess)
Jul 16 '08 #8
JosAH
11,448 Expert 8TB
thanks for the reply, I added these lines (-J-Dderby.storage.pageSize=8m -J-Dderby.storage.pageCacheSize=8m) to netbeans.conf, it shows up as an argument, but doesnt seem to effect the application. it still runs out of memory, i was trying to play with the numbers, but nothing happened.
I suspect the bug to be somewhere else; as I wrote, I did a little test with 100,000
rows and it ran fine, i.e. insert them and select them all. Would it be possible to
show a bit of (relevant) code? Or, alternatively, use the Runtime.freeMemory()
method in the relevant portions of your code and see what happens; also make
sure that you close Derby's resources (result sets, statements etc.)

kind regards,

Jos
Jul 17 '08 #9

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

Similar topics

0
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what...
2
by: Sandy | last post by:
I am doing XSL transformation using xalan, but sometimes the input XML files are too large and that cause "java.lang.OutOfMemoryError: Java heap space" exception in xalan. Is there any way to...
1
by: sunilkumar.r80 | last post by:
Hi I have a problem in reading a .xls file using java. I am using jakarta POI ApI for that it work fine for a 9000 rows contians 25 colums. But i need to read more than 25000 rows (in a single...
14
by: mlw | last post by:
Do not take anything about this, it is not a flame or troll, while I'm not new to Java I favor C++. However, I may need to use it in a contract position, and am concerned that the restrictions it...
0
by: subashinicse | last post by:
hi everybody, am working with J2EE &hibernate... while i run my application,am sending an object(filetype of size more than 8MB) from jboss to securityserver,where am getting ERROR as...
0
by: subashinicse | last post by:
hi everybody, am working with J2EE &hibernate... while i run my application,am sending an object(filetype of size more than 8MB) from jboss to securityserver,where am getting ERROR as...
6
by: nickyeng | last post by:
I keep getting this error: java.lang.OutOfMemoryError: Java heap space what possible reason that cause this error ? My boss dont want increase java memory, so i had to change my code. ...
318
by: King Raz | last post by:
The shootout site has benchmarks comparing different languages. It includes C# Mono vs Java but not C# .NET vs Java. So I went through all the benchmark on the site ... ...
1
by: HxRLxY | last post by:
I have a program that shows a thumbnail of an image. If the user clicks on the thumbnail a new JFrame is opened that shows the full size image. If the image is larger than the screen, it gets...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.