假設(shè)我2個線程同時(shí)對某個單例模式生成的對象進(jìn)行操作,也就是操作的是同一個對象,那豈不是會造成此對象內(nèi)部狀態(tài)的不一致?
ringa_lee
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.