Singleton

1) Eager Loading

Good for small class definitions:

package com.gs.ilp.innerclasses;

/**
 * 
 * Singleton
 * 
 * @author mohitmalhotra
 *
 */
public class StudentUpdateDAOImpl {

	private static StudentUpdateDAOImpl _instance = new StudentUpdateDAOImpl();

	public static StudentUpdateDAOImpl getInstance() {
		return _instance;
	}

	private StudentUpdateDAOImpl() {

	}

	// instance variable

	public void saveStudent() {
		// making save DB
	}

	public int getTotalStudentCount() {
		return 12;
	}

}

2) Lazy Loading

Issue: Thread safety

3) Thread safe - Lazy Loading

4) Thread safe - Lazy Loading - Starvation : performance issue

Double check locking :

Last updated

Was this helpful?