Talk:Lazy initialization

Latest comment: 8 years ago by 67.132.11.102 in topic Too many examples

Too many examples

edit

This article is overrun with examples in 11 different languages; are they really all necessary? The concept is the important part, not the specific implementation. One well-explained example (pseudocode) is likely sufficient to get the idea across--67.132.11.102 (talk) 19:46, 11 July 2016 (UTC)Reply

Java code: thread safety flaw and pertinence

edit

The Java code source snippet use double checked locking. While double checked locking may provide a (infinitesimal) performance gain, it is a controversial technique which tends to make the code less readable (Java concurrency in practice, p.213-214).

Much more importantly, the use of synchronization may lead to think that this class is designed to be thread safe: this is not the case.

Access to the HashMap.contains(), HashMap.get(), HashMap.keySet() methods AND iterating over HashMap.keySet() MUST be synchronized in a multi-threaded environment.

Thread safety is a important concern when using lazy initialization, additional precision is required in the article.

In addition, this snippet would be actually be more pertinent for a caching system, which is way overkill to explain how lazy initialization work. — Preceding unsigned comment added by 217.192.238.66 (talk) 12:15, 26 January 2012 (UTC)Reply

The method getFruitByTypeNameHighConcurrentVersion() in the Java code snippet uses double checked locking and is definitely broken. It should be either removed or updated with a working version. — Preceding unsigned comment added by 217.5.150.53 (talk) 08:29, 20 June 2012 (UTC) Here is a reference as to why double-checked locking as implemented here is broken: http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.htmlReply

merge

edit

Isn't this just a special case of Lazy evaluation? Does it really need its own article? —Preceding unsigned comment added by 64.81.170.62 (talk) 08:46, 15 January 2008

Why the map? Isn't lazy initialization just this:

   private Item _item;
   protected Item item
   {
       get { return _item ?? (_item = new Item()); }
   }

—Preceding unsigned comment added by Doekman (talkcontribs) 19:57, 19 February 2009

Quoting Talk:Lazy_evaluation#merge:

The articles lazy evaluation, lazy initialization, and lazy loading currently don't clearly draw the distinction between them. Is there a clear distinction between them? If so, the articles should be more wp:obvious as to what that distinction is. If not, then we should merge the articles. --68.0.124.33 (talk) 03:33, 4 March 2009 (UTC)

I agree that lazy initialization and lazy loading need more definition than the examples currently provide.
Lazy evaluation is IMHO more often a compiler, or at least lower-level, term. Mark Hurd (talk) 06:59, 4 March 2009 (UTC)

Mark Hurd (talk) 07:09, 4 March 2009 (UTC)Reply

Lazy initialization & Multiton pattern

edit

They are the same in the examples as I see. Maybe add a clarification on what aspect each of the subject is dealing with.

  • Lazy initialization - Instead of creating each time an item, create it once and use it the next time you want to get a new one. Hide from the user the fact that instead of getting a new item, he gets a used one that fits the need. But if you need an item when the conditions changed, then the system would provide you with a new one - this does not reflect in the examples.
  • Multiton - Provide a global list of resources that you cant have more than one for example.

138.134.192.10 (talk) 11:45, 1 August 2011 (UTC)Reply