java - is @Singleton in dagger 2 thread safe? -


i'm trying move in app away singletons, because i've been made aware it's bad programming practice, said, i'm looking implementing dagger 2 dependency injection. , i'm wondering, when @singleton in dagger 2 thread synchronized? if not how can synchronize it, don't strange data anomalies multiple threads touching same things.

when creating singletons before i'd this:

public class somesinglton {     private static classname sinstance;      private somesinglton () {     }      public static synchronized classname getinstance() {         if (sinstance == null) {             sinstance = new classname();         }         return sinstance;     } 

is dagger 2 @singleton equivalent far being synchronized?

as artem zinnatullin mentioned in answer - instance creation of @singleton classes thread safe in dagger.

but if going touch singleton different theads must make thread safe yourself. otherwise dagger won't you.

usually, @singleton annotation should mean other developers such class can used different threads.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -