java - 单例模式中生成的对象是否都要是无状态的?
ringa_lee
ringa_lee 2017-04-18 10:55:45
0
1
496

假设我2个线程同时对某个单例模式生成的对象进行操作,也就是操作的是同一个对象,那岂不是会造成此对象内部状态的不一致?

ringa_lee
ringa_lee

ringa_lee

reply all(1)
黄舟

The singleton mode is inevitably accompanied by multi-threading problems. You can use appropriate locking mechanisms to control it, or ThreadLocal is also a solution. Specific problems should be analyzed in detail. Of course, if it is a stateless class, you don’t need to think so much.

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!