Hi,
I am currently working with guice and dropwizard. I am NOT using the dropwizard-guice dependency since this is somewhat broken with the latest dropwizard version. Fortunatelly I found a nice tutorial explaining how to get this set up so I can use guice. I however have a few issues now, where coming from spring, I am struggling to find the alternative/best practise for it.
Scenario 1:
I have a bean that simply checks at startup that the schema of my database is present. I solved this by doing:
@Provides @Singleton public bla() {
// object
// init
}
The issue is, that I now have to run guice in production. I am feeling that I am abusing the eager singleton creation in production and not doing the right thing here.
How do I create standalone beans that get created and do some work. In spring I would create this and then call an init method on it. In guice I am not sure how to solve this.
Scenario 2:
Timer Tasks that are scheduled or simply threads. E.g. a Monitoring thread that gets metric in and pokes them to a reporting server once a minute. I have the same issue here,
i can create the bean, but I can't call run on it. Also, if I am not in production, since the bean itself is not used anywhere, it won't get created and won't do any work.
It'd be great if someone could give me some pointer for this :)
Thanks,
Artur