假设我2个线程同时对某个单例模式生成的对象进行操作,也就是操作的是同一个对象,那岂不是会造成此对象内部状态的不一致?
黄舟2017-04-18 10:57:45
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.