That makes it sound like a particular deficiency of Java, but it's a
concern in any language/environment where thread-safety is the
responsibility of the programmer. If multiple threads access a mutable
object, either the object is thread-safe or the code is broken.

If you can arrange for access to a singleton to be confined to one
thread, then that object doesn't need to be thread-safe. For example,
most GUI frameworks use a single thread for dispatching and handling
GUI events; you could safely have a singleton root GUI object that was
not thread-safe as long as no other thread -- e.g., a background
computation thread -- accessed that object.

--tim


On Apr 26, 10:30 pm, "Dhanji R. Prasanna" <[email protected]> wrote:
> Unfortunately in Java, Singletons and thread-safety are inextricably linked
> =(
> Dhanji.
>
>
>
> On Mon, Apr 27, 2009 at 7:09 AM, charlesbos73 <[email protected]> wrote:
>
> > Hi,
>
> > back in the days I wrote my own dependency injection framework.
>
> > Really mostly to "grasp" what DI was all about.  And I'm sold :)
>
> > I decided to give Guice a look and one of the very first sentence
> > I find is this:
>
> > "@Singleton indicates that the class is intended to be threadsafe"
>
> > Now this is the most confusing sentence I've read in a while.
>
> > Should it read:
>
> > "@Singleton indicates that the class is intended to be instantiated
> > only once and that this instance shall be re-used (re-injected)"
>
> > (and, hence, of course, that it better be thread-safe, but this is a
> > detail that has nothing to do with what a singleton is).
>
> > Because, really, singletons have nothing to do with thread-safety.
> > Heck, there are languages that aren't multi-threaded that can
> > have singletons.
>
> > Is Guice using the term "singleton" to mean something different
> > than the definition that everyone came to agree on?
--~--~---------~--~----~------------~-------~--~----~
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