Results 1 to 2 of 2
  1. #1
    blackb1rd is offline Member
    Join Date
    May 2014
    Posts
    1
    Rep Power
    0

    Default 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.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default 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.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. strange persisting error
    By willemjav in forum Advanced Java
    Replies: 6
    Last Post: 02-02-2014, 10:52 PM
  2. Persisting POJOs on CDC with db4o
    By german in forum CDC and Personal Profile
    Replies: 0
    Last Post: 05-12-2009, 08:18 PM
  3. sun gives rewards to persisting forum members?
    By willemjav in forum Java Applets
    Replies: 1
    Last Post: 03-27-2008, 05:03 AM
  4. JDO - persisting an object
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-17-2008, 07:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •