java - Examples of use thread safe singleton in multiple threads -


there thread safe singleton, when use singleton in multiple threads? when may helpful?

i use stateless singletons implementations of strategy. being stateless, thread safe , there no problem testing them.

where problems stateful singletons. leads more interactions, in multi-thread context, unit testing stateful singleton in 1 thread pain (i.e. have reset state between tests). reason, many see singletons anti-pattern avoided.

a better approach stateful singletons use dependency injection. way code building components create 1 object, , passed components need it.


Comments

Popular posts from this blog

Lists in Python -

android - can not access to progress bar in an other activity -

java - Vaadin 7 Pass Data Between Views -