Re: Synchronous write to same file using different file pointers



Leonard Milcin wrote:
Can't you just open the file (or the wrapper
class that would guard the access to the file) once, and then inject
that instance to all threads that want to use it?

This is an extremely useful pattern, one I learned as the "Resource Manager", but I don't know if that's any kind of official name for it. Instead of every thread opening its own access to the file directly, they go through this instance of a wrapper class of which Leonard speaks. That instance can use synchronized methods as a coarse-grained way to manage access to the file, or refine its locking strategy for fine-grained control and performance. Its external behaviors will remain consistent, if increasingly performant, as the resource manager abstracts and encapsulates the logic and optimization of concurrent file access.

--
Lew
.