You can keep it in memory as well:
- read from the database when you start your application
- use the in-memory values throughout
- write to the database when the values change
I prefer to write on change instead of write on exit, because the application may not be shutdown nicely by the operating system when it shuts down. That will cause your changes to be lost. The writing can be done in a background thread as to not cause slowness in the user interface.
Note that with database, I do not necessarily mean a database system like MS SQL Server, Oracle or MySQL. A CSV, XML or properties file can be just as good, depending on the contents you want to store.
Joined: Feb 19, 2009
Thanks for the reply.
Is there any limitation to how much data can be kept in the memory.
Have you experienced any disadvantages with it?
By default, 64MB is the JVM limit. That includes everything so also all Strings etc. Usually that's enough though; I usually got into memory problems with complex or image intensive GUIs only, and if the data set stored is just huge. And then we're talking about millions of records.