About 51 results
Open links in new tab
  1. What is an efficient way to implement a singleton pattern in Java ...

    Sep 16, 2008 · Narrowing the question will help others answer the question concisely. You may edit the question if you feel you can improve it yourself. If edited, the question will be reviewed and might be …

  2. On design patterns: When should I use the singleton?

    The glorified global variable - becomes a gloried global class. Some say breaking object-oriented design. Give me scenarios, other than the good old logger where it makes sense to use the singleton.

  3. Implementing the singleton pattern in Java - Stack Overflow

    Jan 5, 2010 · Basically, in Java you implement singleton by giving a class a private no-args constructor (private MyClass()), and statically (or lazily) initializing a single instance of the class which is returned …

  4. Singleton & Multithreading in Java - Stack Overflow

    Jun 17, 2012 · The basic difference is that with the wrapper class version, the singleton instance is created when the wrapper class is loaded, which when the first call the getInstance() is made, but …

  5. java - Regarding static holder singleton pattern - Stack Overflow

    Jun 3, 2014 · The first call to getInstance by any thread causes InstanceHolder to be loaded and initialized, at which time the initialization of the Singleton happens through the static initializer. Static …

  6. java - Thread safety in Singleton - Stack Overflow

    May 26, 2010 · I understand that double locking in Java is broken, so what are the best ways to make Singletons Thread Safe in Java? The first thing that springs to my mind is: class Singleton{ private static

  7. oop - Singleton with Arguments in Java - Stack Overflow

    " A singleton with parameters is not a singleton " -> Singleton pattern: 1) Ensure that only one instance of the singleton class ever exists 2) Provide global access to that instance.

  8. Implementing Singleton with an Enum (in Java) - Stack Overflow

    Oct 10, 2014 · In this Java best practices book by Joshua Bloch, you can find explained why you should enforce the Singleton property with a private constructor or an Enum type.

  9. java - Singleton pattern with combination of lazy loading and thread ...

    Jan 6, 2016 · I was doing some research about singletons, specifically regarding lazy vs eager initialization of singletons. An example of eager initialization: public class Singleton { //initialzed during...

  10. Difference between singleton and factory method pattern

    Apr 27, 2024 · The Singleton pattern ensures that only one instance of the class exists and typically provides a well-known, i.e., global point for accessing it. The Factory pattern defines an interface for …