aspose file tools*
The moose likes Java in General and the fly likes Storing data that changes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Storing data that changes" Watch "Storing data that changes" New topic
Author

Storing data that changes

Justin Howard
Ranch Hand

Joined: Feb 19, 2009
Posts: 162
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

Joined: Oct 27, 2005
Posts: 19719
    
  20

I'd go for a database. That way you have good persistent storage.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Justin Howard
Ranch Hand

Joined: Feb 19, 2009
Posts: 162
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

Joined: Oct 27, 2005
Posts: 19719
    
  20

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

Joined: Feb 19, 2009
Posts: 162
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

Joined: Oct 27, 2005
Posts: 19719
    
  20

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

Joined: Feb 19, 2009
Posts: 162
cool.
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Storing data that changes