java - Singleton service solves multi-process writing files
天蓬老师
天蓬老师 2017-05-17 10:01:08
0
3
941

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!

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(3)
左手右手慢动作

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!