package com.michaelthomas.singleton; /** * @author Michael Thomas (www.michael-thomas.com) michael@michael-thomas.com * * Note: Original concepts came from Wikipedia.com * http://en.wikipedia.org/wiki/Singleton_pattern */ public class SingletonJVMTraditionalExample { /* * Traditional way to create a Singleton. The INSTANCE is created as soon as * the Singleton class is initialized by the JVM. (not lazy) This solution * is thread-safe without requiring special language constructs (i.e. * volatile or synchronized). */ private String name; private static final SingletonJVMTraditionalExample instance = new SingletonJVMTraditionalExample(); // Private constructor prevents instantiation from other classes private SingletonJVMTraditionalExample() { } public static SingletonJVMTraditionalExample getInstance() { return instance; } public void setName(String name) { this.name = name; } public String getName() { return name; } }