Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #11743

Re: Interplatform (interprocess, interlanguage) communication

From Jan Burse <janburse@fastmail.fm>
Newsgroups comp.lang.java.programmer
Subject Re: Interplatform (interprocess, interlanguage) communication
Date 2012-02-04 22:33 +0100
Organization albasani.net
Message-ID <jgk874$njb$1@news.albasani.net> (permalink)
References <IPC-20120203200443@ram.dialup.fu-berlin.de> <5d6ri75i15ei1uv9ill2dgrno1cgd28sho@4ax.com> <268ri7tlv525st589d40efiq0137f0vaag@4ax.com>

Show all headers | View raw


Roedy Green schrieb:
> Let's say you used a simple RandomAccessFile.  How could you implement
> a busy lock field in the file to indicate the file was busy being
> updated? or busy being read?  In RAM you have test and set locks to
> check a value and set the value in one atomic operation.  How could
> you simulate that without test and set hardware on the SSD? You can't
> very well share a RAM lock between separate jobs.

What do you want, a write lock or a read lock?
Here is a write lock:

Obtain the lock:
                 raf = new RandomAccessFile(file, "rw");

                 fo = new FileOutputStream(raf.getFD());
                 fo.getChannel().lock(0, Long.MAX_VALUE, false);

Release the lock:
                 fo.close();

		raf.close();

Maybe it can be done even simpler, but the above
works for me over process / jvm boundaries. Can
be also used to synchronize jvm with non-jvm code.

Similar code I use to obtain a read lock, via an
FileInputStream and the lock() methods third
argument =true. Currently seems also to work on
Android, but did not yet thoroughly test...

Bye

(*)
http://docs.oracle.com/javase/1.4.2/docs/api/java/nio/channels/FileChannel.html#lock%28long,%20long,%20boolean%29

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Interplatform (interprocess, interlanguage) communication Roedy Green <see_website@mindprod.com.invalid> - 2012-02-04 12:50 -0800
  Re: Interplatform (interprocess, interlanguage) communication Roedy Green <see_website@mindprod.com.invalid> - 2012-02-04 13:22 -0800
    Re: Interplatform (interprocess, interlanguage) communication Jan Burse <janburse@fastmail.fm> - 2012-02-04 22:33 +0100
      Re: Interplatform (interprocess, interlanguage) communication Roedy Green <see_website@mindprod.com.invalid> - 2012-02-12 04:30 -0800
    Re: Interplatform (interprocess, interlanguage) communication Arne Vajhøj <arne@vajhoej.dk> - 2012-02-04 18:42 -0500
  Re: Interplatform (interprocess, interlanguage) communication Arne Vajhøj <arne@vajhoej.dk> - 2012-02-04 18:39 -0500

csiph-web