I am trying to move everything in my application alone because I became aware that this is a bad programming practice and I said that I am studying dagger 2 dependency injection. And I wonder when you do @Singleton in Dagger 2, this thread is synchronized ? if not, how can I synchronize it, so I don’t get any strange data anomalies from multiple streams affecting the same things.
When I created singlets, before I would 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 equivalent of @ @ Singleton's dagger until it synchronizes?
source share