Question

I don't found solution for my problem. But i have a simple case -

  1. I have many threads, each other is write strings to file.
  2. Any threads writing into the same files.
  3. I need to close all files only after all threads will end.

But problem is - I need to keep open all files during threads execution and closing all ONLY AFTER when all threads will end. But when I use FileDescriptors after all threads were completed - all descriptors are not valid. I think, if I'm "flush" output stream, instead of using "close" method - all is ok, but, maybe, I was wrong:

FileOutputStream fileOutputStream = new FileOutputStream(url, true);
fileDescriptor = fileOutputStream.getFD();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(fileOutputStream, "UTF-8"));
writer = new PrintWriter(bufferedWriter);
...
writer.flush;

But the main question is - it is really - what all output stream is closing after thread is ended? And, if yes, how to keep opened files between threads?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top