Guest User

Untitled

a guest
Feb 18th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. package com.systems.singleton;
  2.  
  3. /*
  4. *Singleton With Lazy Initialization
  5. */
  6.  
  7. public class DataBase {
  8. private int record;
  9. private String name;
  10. private static volatile DataBase singleTon = null;
  11.  
  12. private DataBase(String n) {
  13. name = n;
  14. record = 0;
  15. }
  16.  
  17. public void editRecord(String operation) {
  18. System.out.println("Performing a " + operation + " operation on record " + record + " in database " + name);
  19. }
  20.  
  21. public String getName() {
  22. return name;
  23. }
  24.  
  25. public static DataBase getInstance(String n) {
  26. if (singleTon == null) {
  27. synchronized (DataBase.class) {
  28. if (singleTon == null)
  29. singleTon = new DataBase(n);
  30. }
  31. }
  32. return singleTon;
  33. }
  34. }
Add Comment
Please, Sign In to add comment