-1

Is there any way to share the same data with different processes which run on the same local machine but run in different JVMs ?

Mimian
  • 11
  • 6
  • Yes, there are many, many ways. Perhaps if you elaborate on what you are trying to do...? – azurefrog Sep 13 '16 at 16:46
  • 1
    @azurefrog I'm having some troubles with a project im working on, i explain it better in here http://stackoverflow.com/questions/39455159/update-data-in-java-in-multiple-processes-active-on-the-same-time?noredirect=1#comment66232077_39455159 thank you if you read it :) – Mimian Sep 13 '16 at 16:52

1 Answers1

3

You can get a shared-memory effect from memory-mapped files. The same file's data can be mapped into the address space of an arbitrary number of processes. As far as I know, this is the lowest-latency, highest-throughput approach in existence. Your data truly is in RAM and the same physical pages originally belonging to the disk cache are mapped into several processes's address space.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
  • Thank u for ur answer but how can i make it possible ? I'm having some troubles with a project im working on, i explain it better in here http://stackoverflow.com/questions/39455159/update-data-in-java-in-multiple-processes-active-on-the-same-time?noredirect=1#comment66232077_39455159 thank you if you read it :) – Mimian Sep 13 '16 at 17:01
  • @Mimian: don't re-ask your questions please – Hovercraft Full Of Eels Sep 13 '16 at 17:05
  • @markotopolnik the idea is that if i save the list (which i want all processes to have the same), anytime one of the processes makes changes on it, the change will be visible in all the processes? – Mimian Sep 13 '16 at 18:25
  • You'll have to check out the details in terms of concurrent updates to the file. There may be limitations there. For a single writer this will certainly work; for multiple writers I don't have enough information. – Marko Topolnik Sep 13 '16 at 18:27
  • in my case i have different processes trying to change the same list, and what i want is that once a difference of the list is done, all active processes to get to know that and maybe to update somehow the old value of the list they had. its kinda complicated – Mimian Sep 13 '16 at 18:31
  • If I got you right, each process has its own part of the list that it's updating. In that case each process can have its own file open for writing and all other process's files open for reading. – Marko Topolnik Sep 13 '16 at 18:33
  • kinda that, if i can be more specific the idea is that i have one list which saves all sensors (where one sensor is a process apart) the data on the list gets updated every time i start a new process sensor. The problem is that once added a new process the other existing ones cant 'see' the new one is added cause the list they have is the old one, so i cant make it possible to somehow update the list of all the active processes – Mimian Sep 13 '16 at 18:47
  • You might want to consider something like Hazelcast (disclosure: I work for them). You'd get automatic connection between all the processes and a simple Map API to put your data into. And you can listen to update events. – Marko Topolnik Sep 13 '16 at 19:40
  • its the first time i hear about it and sincerely i've seen some examples but its not very clear. How am i supposed to work with it? Ps: i must say that my java level is not advanced, just a few months using it, im still a student :) – Mimian Sep 13 '16 at 19:59
  • It's far more advanced to create what you need from the raw component of a memory-mapped file than to use a library that does everything for you. – Marko Topolnik Sep 14 '16 at 06:32