Sharing Data Between App Instances

Discussion in 'Java' started by Mike, Dec 27, 2006.

  1. Mike

    Mike Guest

    Forgive me; this is sort of a newbie question. Is it possible to share in-
    memory data between instances of an app?

    I realize I could just write the info to disk with one instance then read
    it into the other instances from the disk, but I'd like to keep it in
    memory for performance reasons.

    This data may need to be accessed simultaneously by separate instances in a
    read-only fashion. Only one instance will ever modify the data. It's
    possible that attempts to read and update the data simultaneously may occur
    so the code would need to support some type of locking.

    Hopefully this question makes sense to someone besides me ;) Any code
    needs to work on JVM version 1.4 (in case that matters.)

    Thanks in advance! This group has been infinitely useful in my learning.
    Hopefully soon I'll be able to contribute.

    - Mike
     
    Mike, Dec 27, 2006
    #1
    1. Advertising

  2. Mike

    Oliver Wong Guest

    "Mike" <> wrote in message
    news:Xns98A6AC1FDE322replytogroup@216.196.97.131...
    > Forgive me; this is sort of a newbie question. Is it possible to share
    > in-
    > memory data between instances of an app?
    >
    > I realize I could just write the info to disk with one instance then read
    > it into the other instances from the disk, but I'd like to keep it in
    > memory for performance reasons.
    >
    > This data may need to be accessed simultaneously by separate instances in
    > a
    > read-only fashion. Only one instance will ever modify the data. It's
    > possible that attempts to read and update the data simultaneously may
    > occur
    > so the code would need to support some type of locking.
    >
    > Hopefully this question makes sense to someone besides me ;) Any code
    > needs to work on JVM version 1.4 (in case that matters.)
    >
    > Thanks in advance! This group has been infinitely useful in my learning.
    > Hopefully soon I'll be able to contribute.


    Writing to disk is probably the easiest way. Another might be for the
    first instance (or the read/write instance) to act as a server and listen on
    a port. Other instances could then try to listen on the same port, and upon
    discovering that it's already in use, realize that they are "secondary
    instances", and then act like clients, connecting to that port.

    As a newbie, I'd probably go for the easiest solution (which may or may
    not be the file based one), and not worry about performance unless it
    actually turns out to be a problem under real world usage.

    - Oliver
     
    Oliver Wong, Dec 27, 2006
    #2
    1. Advertising

  3. Mike wrote:
    > Forgive me; this is sort of a newbie question. Is it possible to share in-
    > memory data between instances of an app?
    >
    > I realize I could just write the info to disk with one instance then read
    > it into the other instances from the disk, but I'd like to keep it in
    > memory for performance reasons.
    >
    > This data may need to be accessed simultaneously by separate instances in a
    > read-only fashion. Only one instance will ever modify the data. It's
    > possible that attempts to read and update the data simultaneously may occur
    > so the code would need to support some type of locking.
    >
    > Hopefully this question makes sense to someone besides me ;) Any code
    > needs to work on JVM version 1.4 (in case that matters.)
    >
    > Thanks in advance! This group has been infinitely useful in my learning.
    > Hopefully soon I'll be able to contribute.
    >
    > - Mike


    Don't assume that every read of a shared file will cause a physical disk
    read. Most operating systems do some disk caching, so frequently
    accessed blocks may be in memory anyway.

    Try whatever approach seems simplest first, and measure it. Make sure
    you isolate the shared data access in your class design, so that the
    implementation can be changed without rewriting the program.

    Patricia
     
    Patricia Shanahan, Dec 27, 2006
    #3
  4. Mike

    Lew Guest

    > Mike wrote:
    >> Forgive me; this is sort of a newbie question. Is it possible to
    >> share in-
    >> memory data between instances of an app?
    >>
    >> I realize I could just write the info to disk with one instance then
    >> read it into the other instances from the disk, but I'd like to keep
    >> it in memory for performance reasons.


    Patricia Shanahan wrote:
    > Don't assume that every read of a shared file will cause a physical disk
    > read. Most operating systems do some disk caching, so frequently
    > accessed blocks may be in memory anyway.


    Would NIO memory-mapped files work here? Or some other NIO magic with direct
    buffers?

    I am speculating, because I am (shamefacedly) only just getting around to
    learning NIO.

    - Lew
     
    Lew, Dec 27, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    412
  2. John Wohlbier
    Replies:
    2
    Views:
    369
    Josiah Carlson
    Feb 22, 2004
  3. Replies:
    1
    Views:
    252
    Steve Holden
    Aug 15, 2006
  4. Leon Bogaert
    Replies:
    6
    Views:
    146
    ara.t.howard
    May 11, 2008
  5. Derek Basch

    Sharing a socket between instances

    Derek Basch, Jul 31, 2006, in forum: Perl Misc
    Replies:
    5
    Views:
    158
Loading...

Share This Page