Answers for "thread-safe singleton class in java"

0

threadsafe singleton pattern in java

package com.journaldev.designpatterns;

public class ASingleton {

	private static volatile ASingleton instance;
	private static Object mutex = new Object();

	private ASingleton() {
	}

	public static ASingleton getInstance() {
		ASingleton result = instance;
		if (result == null) {
			synchronized (mutex) {
				result = instance;
				if (result == null)
					instance = result = new ASingleton();
			}
		}
		return result;
	}

}
Posted by: Guest on June-16-2020

Code answers related to "thread-safe singleton class in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language