• 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

Database loading/saving

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried some things with databases and I was wondering if it is faster to use a HashMap with an XML file or to just serialize the HashMap.

Either way the system runs from constantly accessing this map, I just want to know the fastest way to load on start-up and save on exit.

Thanks much
 
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Derek,

unfortunately my last (long) post got lost because there was some problem with the connection to JavaRanch

So here once again in short:

I'm not sure if I got you right and I don't know how this is related to databases. But as I understand your problem you use a HashMap as in-memory database and now you want to save it to and load it from disk?!? Hope this is correct...

Java serialization will be more compact and therefore faster because it's a binary data format. To work correctly the whole object graph of all things you put into the map have to be serializable. If this is no problem and you only have Java applications using these data then serialization is an option.

XML on the other hand is more verbose because it's text data. So the disadvantage is clearly that it produces more I/O overhead and therefore it will be slower, in particular if you have lots of data. The advantages are that the data will be human readable and editable. You can use lots of tools and other programming languages to edit or read the data because it's highly interchangeable. To load and save the data there are many APIs and libraries you can use in Java depending on your needs. For this it's difficult to give a good advice without knowing your requirements and some more details about the data and application. Possible ways to use XML in Java that come to mind are the following APIs and libs: SAX, DOM, StAX, JAXB, xstream and others...

Marco
 
Derek White
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Marco, your answer was definitely what I was looking for.
I am using an Object[] to store/load entries from a server, and I have little or no need for a human readable format.
 
Marco Ehrentreich
best scout
Posts: 1294
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Derek, you're welcome ;-)

Unfortunately it seems that things are getting more complicated... We have a database I don't know anything about. And now we even have a server I don't know anything about. And of course an array of Objects in contrast to the HashMap in XML you were talking about a few lines above

This is definitely a little bit confusing. Did my advices help you to find a solution? Or do you have problems or questions at the moment? If you still need some help it would probably be helpful to hear the whole story about your application

Marco
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will probably get faster load/store time using serialization than a HashMap. However, you will almost certainly blow up the first time you upgrade Java and the serialized format has changed and become incompatible, as it often does. Serialization is better used for short-term persistence and over-the-wire transmittion, and not always even then.

Depending on the environment, you may actually find it faster and simpler to put that data in a database and use an ORM such as JPA, Hibernate, or even EJB to manage it. Frequently-accessed items will stay in cache transparently, infrequently-accessed items will be left in persistent store where they won't consume RAM.
 
Arthur, where are your pants? Check under this tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic