Re: Interplatform (interprocess, interlanguage) communication



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
.



Relevant Pages

  • Re: Intra-thread lock
    ... Is there something like an intra-thread lock? ... since my code is triggered by a gui event, ... having a private variable "busy" and setting that to true when I start ... my problem is that I have an app with potentially many ...
    (microsoft.public.dotnet.framework)
  • Re: Intra-thread lock
    ... design of gui events that are in fact window messages. ... busy flag is false, ... Is there something like an intra-thread lock? ... re-entrant code, and the lock statement will only prevent one thread ...
    (microsoft.public.dotnet.framework)
  • Re: Interplatform (interprocess, interlanguage) communication
    ... a busy lock field in the file to indicate the file was busy being ... very well share a RAM lock between separate jobs. ...
    (comp.lang.java.programmer)
  • Re: First day out this year - almost a disaster.
    ... I single hand a lot, and the problems are always in getting on and off the ... you hope you won't ned them; keep spare fenders, ... For the lock I rigged four lines, two each side, so if I can't get ... ideal place because there isn't a lot of room, and it can be busy. ...
    (uk.rec.sailing)
  • Re: Intra-thread lock
    ... Is there something like an intra-thread lock? ... having a private variable "busy" and setting that to true when I start ... While GUI event is being processed, you can be sure that it will _not_ be fired a second time because the windows message loop is blocked until your processing is done. ... Either by throwing an exception or by enqueuing the new work item somewhere for later processing. ...
    (microsoft.public.dotnet.framework)