I am trying to write a single huge file in Java using multiple threads.
I have tried both FileWriter
and bufferedWriter
classes in Java.>
Instead of having a synchronized methods, the better solution would be to have a threadpool with single thread backed by a blocking queue. The message application would be writing will be pushed to blocking queue. The log writer thread would continue to read from blocking queue (will be blocked in case queue is empty) and would continue to write it to single file.