I’m writing a Java program that performs a few millions of unit computation. Each unit would take around 1 sec, so overall it would take a few days to finish. After computing each unit, I want to write some results (a few lines of text) into a file. Since writing files takes time, I wonder whether I should create a separate thread for writing files, so it wouldn’t block the main computation.
Thank you.
I assume you are running on mainstream OS, not exotic one. If you just write to
FileOutputStreamand do not doflush()on it, the data will most probably be written into memory buffer, which takes virtually no time. Real write on disk will happen later asynchronously, so don’t mind.