Now we need a multi-process file writing program
If you write directly, you need to ensure that the process locks the file handle
Now I want to register a singleton writing service through spring
When multiple programs write files, they request the spring interface to write files
Is this solution feasible?
Or use a singleton RPC service?
A single instance can ensure that it is an instance when writing a file, avoiding multi-thread and multi-process synchronization problems!
I think this is still not possible. Essentially, Spring only manages instances for you, and you still have to solve the issue of thread safety yourself
Furthermore, you are talking about writing files through multiple processes. RPC is only a multi-threading method, right?
In fact, the essence is to implement a thread-safe file writing interface. Singleton is OK, just use your own instance as a lock
=_=! A multi-process program?
Using zookeeper, a characteristic of zookepper is that only one client (process) can successfully write to the same znode. Use this client to write files, or use the database to write the same primary key. Only one can insert successfully