Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.systems.singleton;
- /*
- *Singleton With Lazy Initialization
- */
- public class DataBase {
- private int record;
- private String name;
- private static volatile DataBase singleTon = null;
- private DataBase(String n) {
- name = n;
- record = 0;
- }
- public void editRecord(String operation) {
- System.out.println("Performing a " + operation + " operation on record " + record + " in database " + name);
- }
- public String getName() {
- return name;
- }
- public static DataBase getInstance(String n) {
- if (singleTon == null) {
- synchronized (DataBase.class) {
- if (singleTon == null)
- singleTon = new DataBase(n);
- }
- }
- return singleTon;
- }
- }
Add Comment
Please, Sign In to add comment