mardi 20 janvier 2015

Blocking file read in Java

I'd like to set up a blocking file read in Java. That is, have a file such that when wrapped by FileInputStream and any read() method is call, the call blocks.


The purpose is to examine stack of the method to determine what the top frames are in such a case, but why I want it is more or less besides the point.


I can't think of an easy OS-independent way - on Unix-like OSes I could try to create a FIFO using mkfifo and read from that file. A possible work around would be to just create a very large file and read from that - the read is unlikely to complete before I capture the stack, but it's ugly and slow (and indeed reads can still be incredibly fast when cached).


The corresponding socket read() case is trivial to set up - create a socket yourself and read from it, and you can have deterministic blocking.


Aucun commentaire:

Enregistrer un commentaire