ha9u63a7
ha9u63a7

Reputation: 6804

Difference between @Singleton and asEagerSingleton()

I have a project where I see my service is failing to initialise.

I am using Dropwizard-guicey - but it uses Guice underneath, and my question is specific for Guice because the dependency injection is the theme here.

I am attaching the link to the same question I added in Guice Github area. The project file attachment is there, (sorry SO doesn't have attachment option).

The class - TheProblemClass extends AbstractScheduledService (Guava) and implements Managed interface in Dropwizard.

The idea is that I ought to be able to start/stop the service upon Main server startup and shutdown respectively. Also, I could schedule a periodic call to one of its methods. OK - besides the sniff that it's doing 3 things in one class, it's functional.

Some things I have noticed.

  1. When TheProblemClass is annotated with @Singleton - it is working fine.
  2. When TheProblemClass is NOT annotated with @Singleton - it is always hanging. In my Module - I have bound it as an eager singleton. My understanding was that I only needed to do this in one place. And the rest should be OK. Have I misunderstood how Singleton Annotation and Module Configs are supposed to be working together?

Upvotes: 0

Views: 33

Answers (0)

Related Questions