mardi 30 juin 2015

what are the concern regarding simultaneous read and write to a file?

consider the following scenario:

  1. Process 1 (Writer) continuously appends a line to a file ( sharedFile.txt )
  2. Process 2 (Reader) continuously reads a line from sharedFile.txt

my questions are:

In java is it possible that :

  1. Reader process somehow crashes Writer process (i.e. breaks the process of Writer)?
  2. Reader some how knows when to stop reading the file purely based on the file stats (Reader doesn't know if others are writing to the file)?

to demonsterate

Process one (Writer):

...
while(!done){
 String nextLine;//process the line
 writeLine(nextLine);
 ...
}
...

Process Two (Reader):

...
while(hasNextLine()){
  String nextLine= ReadLine();
  ...
}
...

Aucun commentaire:

Enregistrer un commentaire