Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Sharing Data Between App Instances

Reply
Thread Tools

Sharing Data Between App Instances

 
 
Mike
Guest
Posts: n/a
 
      12-27-2006
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
 
Reply With Quote
 
 
 
 
Oliver Wong
Guest
Posts: n/a
 
      12-27-2006
"Mike" <(E-Mail Removed)> 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


 
Reply With Quote
 
 
 
 
Patricia Shanahan
Guest
Posts: n/a
 
      12-27-2006
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
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      12-27-2006
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sharing variables between classes and instances Leon Bogaert Ruby 6 05-11-2008 05:50 PM
Making a multithread app that runs several instances of whatever the app did before olbion@gmail.com Python 1 08-15-2006 10:17 AM
Sharing a socket between instances Derek Basch Perl Misc 5 07-31-2006 10:00 PM
Sharing objects between class-loader instances tom@conjective.ch Java 0 12-13-2005 03:01 PM
list of class instances within a list of a class instances John Wohlbier Python 2 02-22-2004 08:41 AM



Advertisments