Results 1 to 2 of 2
- 05-17-2014, 10:22 PM #1Member
- Join Date
- May 2014
- Rep Power
Best practice for persisting objects
I'm building an application that downloads a set of images from a website, extracts some features from them and then allows a user to compare an image she submits to the downloaded set, to see which one is the closest. At the moment the application downloads the images and extracts the features from them. Then the image and the feature get wrapped in an object and stored in a map, with the key as the name of the image, and the value as the aforementioned wrapped object.
Because this is stored in memory, each time I start the application it has to go through the quite expensive process of downloading and feature extraction. It would be much quicker if it could just load this info from disk, but I'm not sure on the best way to go about it - I've thought about these options:
- RDMS: something like Postgres or SQLite
- NoSQL: something like Voldemort or Reddis
- Serialisation: use built in java methods to write objects to a file (could also be used in conjunction with a DB though...)
I want it to be really light weight; I want to keep the application as small as possible and keep configuration down to a minimum. For this reason serialisation seems like the way to go, but I'd like a second (or more) opinion on that, because something about doing it that way just feels wrong. I can't quite put my finger on why I feel like that...
I should also say that users can add images to the set when the application is running, I'd like to save these images too.
- 05-18-2014, 09:00 AM #2
- Join Date
- Sep 2008
- Voorschoten, the Netherlands
- Blog Entries
- Rep Power
Re: Best practice for persisting objects
The only aspect that makes it 'heavy weight' are the images themselves (especially when they're large and/or there are a lot of them; it can take up a lot of internal memory). Serialization of a Set of Features of those images is fine (imho) and I'd make such a Features object a 'proxy' for an image, i.e. only when the image is needed, it is loaded in memory (and possible cached for later use); the Serialization can be to/from simple files or to/from a DB, it doesn't matter much; if multiple users can add/remove Feature objects, a bit of synchronization can handle it ... flushing (writing back) to persistent storage shouldn't be much of a problem either ... Also have a look at the WeakReference and WeakHashMap classes.
Joscenosillicaphobia: the fear for an empty beer glass
- By willemjav in forum Advanced JavaReplies: 6Last Post: 02-02-2014, 10:52 PM
- By german in forum CDC and Personal ProfileReplies: 0Last Post: 05-12-2009, 08:18 PM
- By willemjav in forum Java AppletsReplies: 1Last Post: 03-27-2008, 05:03 AM
- By Java Tip in forum Java TipReplies: 0Last Post: 03-17-2008, 07:45 AM