I'm trying to move everything in my app away from singletons, because I've been made aware that it's a bad programming practice, with that said, I'm looking into implementing Dagger 2 dependency injection. And I'm wondering, when you do @Singleton in Dagger 2 is that thread synchronized? if not how can I synchronize it, so I don't get any strange data anomalies from multiple threads touching the same things.
When I was creating singletons before I'd do something like this:
public class SomeSinglton {
private static ClassName sInstance;
private SomeSinglton () {
}
public static synchronized ClassName getInstance() {
if (sInstance == null) {
sInstance = new ClassName();
}
return sInstance;
}
is the Dagger 2 @Singleton equivalent as far as being synchronized?