I am converting an object (ArrayList) in XML and then storing that XML as a file on local machine. When there are large number of data, the XML takes too long to write in a File or doesnt write at all (gives some exception).
xmlSource = xmlConverter.convert(object); // object here is no.of ArrayLists..
Using BW does speed up the process by almost 40%, although the PC remains in a numb state during that time..but it does work..
I m afraid this solution is not gonna be enough as there are around 100k entries on Production env at max.. ( I checked above sol. on 50000 records..)
Is there any possibility that i split the records and then in chunks i add them in "same file". (dont want to create more than 1 XML for one page..)
Thanks again...
batuk chatuk
Greenhorn
Joined: Dec 29, 2006
Posts: 12
posted
0
Its Done!!!
File writing is happening totally with all data at a time in above code.. So this is the answer to better and memory friendly code...
xmlSource = xmlConverter.convert(obj); BufferedReader bufferedReader = new BufferedReader(xmlSource.getReader()); PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(f))); int count = 0; int buffer=1024; char[] c1=new char[buffer]; while((count = bufferedReader.read(c1, 0, buffer)) != -1){ pw.write(c1, 0, count); } pw.flush(); pw.close();
batuk chatuk
Greenhorn
Joined: Dec 29, 2006
Posts: 12
posted
0
For 100K records or more the above code didnt work on my machine.. ( i had kept JVM Heap size to Max. 1300K.. ) The reason was the XMLConverter was not able to convert that much data into XML So i wrote the code to divide all the ArrayLists in chunks and then convert them and write them into the same file..