• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Writing text to xml is taking too long --Java

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some 3000 elements in arraylist.Need to write these 3000 elements to xml. The execution is taking too much time like 20 minutes in eclipse. Is there any efficient way to do this? OR any modifications to my code?

The elements in arraylist are supposed to grow in future...

MY code snippet..

 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you profiled your application to see where the execution time is spent. 20 minutes suggests a more fundamental problem to me.
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At first glance it seems that you're opening a file and initializing the entire DOM infrastructure for each element of the list - you should do that once, and write all elements in one go.
 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf, I see what you mean. So this invocation is simply outputting a single node (called fullname) to the file. This is then repeated 3000 times? Sarah, can you confirm? If this is the case, that is indeed the fundamental problem.
 
sarah sainy
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Modified my code like below



I was doing the following operations repetitively
1.opening the file,
2. parsing the document
3. Add an element to the DOM
4. flush the file to disk

Now i am doing step1,2 and 4 only once.

This solves the problem.Execution time is less than 2 minutes now
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sarah

Looking at the code, you have posted, there are some compiler errors in there. For example, this are no such constructors as File(File) or File(Document). Also, your WriteToXML method has no return type. In future, it would be easier for those giving you help if you posted the exact code you are using.
 
reply
    Bookmark Topic Watch Topic
  • New Topic