Is it safe to call write on Java FileOutputStream object form multiple threads? Will the output be serialized correctly?
clarification:
In my case the class logger holds a FileOutputStream reference, and multiple threads can call logger write, that formats the output and calls FileOutputStream write.
Should I synchronize my logger write method to warrant that the messages from multiple threads are not mixed?
解决方案
A file can not be opened more than once in write-mode, so the answer is no.
After seeing your edit, yes you should introduce synchronization into your logger to make sure the stream is accessed only by one thread at a time. Just a suggestion, why don't you go for Log4J? It already handles your use case.