On Thu, Jan 15, 2009 at 12:04 PM, Rick <[email protected]> wrote:
>
>
> On Wed, Jan 14, 2009 at 7:23 PM, Dhanji R. Prasanna <[email protected]>wrote:
>
>> This code is not thread-safe. =(
>> This is exactly why encourage people to use Guice singletons and
>> discourage the traditional singleton (anti-)pattern.
>>
>
> Can you explain (or a use case) where using an Enum as Singleton would be
> an issue. Even under a single classloader the enum isn't thread safe?
>
It's not the enum that's the problem, it's the lazy creation of the
injector:
private Injector getInjector() {
if (injector == null) {
injector = Guice.createInjector(getModules());
}
return injector;
}
This can lead to multiple injectors being created concurrently, and worse:
to partially created injectors being visible from other threads.
Dhanji.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---