No, a Guice @Singleton doesn't have the problems that the Singleton pattern
has, since it doesn't involve a static instance or a lookup mechanism that
causes tight coupling. It just involves Guice internally ensuring that it
only creates 1 instance. The main things to consider when deciding whether
or not to make something @Singleton in Guice are:

1) Does the class have state that needs to be shared between all clients of
it and does it need to stick around for the lifetime of the application? If
so, it needs to be a singleton.
2) If not, it depends on how you're using it. It should be faster to inject
a non-singleton, so if it's going to be injected a lot (during web requests,
say) don't bother making it a singleton. On the other hand, if it's being
used in 10 other classes that are all singletons, it might as well be a
singleton too to save a little memory.

-- 
Colin


On Thu, Apr 21, 2011 at 6:35 PM, Andy <[email protected]> wrote:

> Do the same advantages and disadvantages apply to the “Singleton
> Pattern”, as using @Singleton in Guice. (
> http://stackoverflow.com/questions/137975/what-is-so-bad-about-singletons
> )
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to