Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37905
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Guice vs plain singleton |
| Date | 2017-12-22 20:11 -0500 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <p1kafp$10rq$1@gioia.aioe.org> (permalink) |
| References | <p1e2jv$1jmk$1@gioia.aioe.org> <p1e4i8$3rc$1@newsreader4.netcologne.de> <p1gb9a$t9s$1@dont-email.me> <28fcb1d3-0fa4-48c0-a6f2-972e727cb874@googlegroups.com> |
On 12/21/2017 2:36 PM, lewbloch@gmail.com wrote:
> On Thursday, December 21, 2017 at 5:00:45 AM UTC-8, Daniele Futtorovic wrote:
>> On 2017-12-20 17:53, Patrick Roemer wrote:
>>> Responding to Victor Porton:
>>>> What should I prefer for creating a singleton object with "heavy" (requiring
>>>> much CPU time or like this) constructor:
>>>>
>>>> - Guice @Singleton injector
>>>>
>>>> or
>>>>
>>>> - plain hand-made singleton like
>>>>
>>>> static Type instance; ... if(instance==null) ...
>>>>
>>>> ?
>
> public enum Singletary
> {
> INSTANCE;
>
> // constructor, methods, ...
> }
>
> This has been solved and published since, oh, 2008, when the second edition of _Effective Java_ came out.
It is certainly the most smart way from a Java technology point of view.
Significant less code than the alternatives.
But even with all due respect to the other Bloch then I do not
consider it good code.
It is using some very Java specific characteristics of an enumeration
to provide some functionality that is not related to being an
enumeration.
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Guice vs plain singleton Victor Porton <porton@narod.ru> - 2017-12-20 18:19 +0200
Re: Guice vs plain singleton Patrick Roemer <sangamon@netcologne.de> - 2017-12-20 17:53 +0100
Re: Guice vs plain singleton Daniele Futtorovic <da.futt.news@laposte.net> - 2017-12-21 13:59 +0100
Re: Guice vs plain singleton lewbloch@gmail.com - 2017-12-21 11:36 -0800
Re: Guice vs plain singleton Arne Vajhøj <arne@vajhoej.dk> - 2017-12-22 20:11 -0500
Re: Guice vs plain singleton Sebastian <nowhere@nirvana.org> - 2017-12-23 16:15 +0100
Re: Guice vs plain singleton lewbloch@gmail.com - 2017-12-23 09:54 -0800
Re: Guice vs plain singleton Arne Vajhøj <arne@vajhoej.dk> - 2017-12-23 19:27 -0500
csiph-web