Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Storing data that changes

 
Justin Howard
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

This question is probably asked very frequently.

How can I store data (eg email list) that is updated once in a few months.

Currently I have such data in the Constants file, but I can see why its bad practice.

Any articles that I can refer to will be helpful too.

Thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd go for a database. That way you have good persistent storage.
 
Justin Howard
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply.
Suppose I use this data very often in the application. Every email that is sent out etc.

Would it still be better to store it in the database.

Thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Justin Howard
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Justin Howard
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cool.
Thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic