0

I use singletone classes, are injected by dagger. But if synchronized methods start running, but they terminates. But if I remove synchronization from methods, they run well. If I inject sungletone classes by dagger, I shouldn't use synchronized methods?

user3057944
  • 701
  • 1
  • 8
  • 19

1 Answers1

4

Dagger and Dagger 2 singletons and scoped providers use internal double-checked synchronization. If you're writing a singleton @Provides method, it will be called exactly once in a synchronized environment, so you probably won't need to worry about it.

Unless your @Provides method does anything thread-unsafe and is expected to be called multiple times, don't worry about marking anything synchronized.

researcher
  • 1,758
  • 22
  • 25
Jeff Bowman
  • 90,959
  • 16
  • 217
  • 251