Thank you for your response! I was considering something like locking the files individually, but I was wondering, wouldn't this end up blocking threads if the file writing process took too long? I wasn't sure how to go about making sure I don't end up locking up the program because a file took too long to write to or something.
If a file takes too long to write you want it to block because you don't want another thread to start writing to the same file. Within the thread you could have a timer and fire off an event for the thread to exit after a certain amount of time. Check out the java.util.timer class.
I just thought of maybe using a LinkedBlockingQueue that stores an object which contains the file to write to, as well as what to write and using a consumer thread to go through and save the files, however I ended up again at the problem of if a file takes too long, then the consumer thread locks up and nothing saves in time.
I am not familiar with this as I have never used it. But the timer solution still applies.
Overall you could have a thread pool of available threads to run to write to the files. If you run out of threads you can simply have a queue for the requests for the next free thread to process. But there is always the potential of either running out of threads and having the writes take too long or having a timer and not completely writing the information. How you deal with that is up to you but if the thread locks up and never releases due to a long write, there is definitely a bug in your code. All writes must eventually end, even with an I/O error.
Regards,
Jim