6

I was wondering how you would synchronize on a memory-mapped file to safely use it as a pipe between two JVMs. Has anyone done that before with success?

JohnPristine
  • 3,485
  • 5
  • 30
  • 49
  • 1
    It might help desribing your use case as this seems to be a fairly uncommon requirement. – home Nov 17 '12 at 20:21
  • Why not just use a pipe and let the OS take care of it? Inter-JVM synchronisation is, I strongly suspect, inherently non-portable. – Alan Stokes Nov 17 '12 at 20:44
  • I think a similar (if not duplicate) [discussion](http://stackoverflow.com/questions/1491519/any-concept-of-shared-memory-in-java) was held here before. – mindas Nov 17 '12 at 20:58

1 Answers1

2

I have a library which does this but it doesn't use synchronization. It writes once to memory rather than reusing the memory which simplifies the memory model. Java Chronicle

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • 1
    How does the consumer poll for new data in the memory-mapped file? What do you do when you eventually have to roll the memory-mapped file? – JohnPristine Nov 17 '12 at 20:33
  • The consumer polls or busy waits. I don't roll the memory mapped file. I assume there is enough disk space to last a day or a week and the application will be restarted to roll the files. Few applications need more than a couple of TB a day of data. – Peter Lawrey Nov 17 '12 at 21:03