Advertisement
jaVer404

level17.lesson04.task04

Sep 24th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. package com.javarush.test.level17.lesson04.task04;
  2.  
  3. /* Синхронизированный президент
  4. И снова Singleton паттерн - синхронизация в статическом блоке
  5. Внутри класса OurPresident в статическом блоке создайте синхронизированный блок.
  6. Внутри синхронизированного блока инициализируйте president.
  7. */
  8.  
  9. public class Solution {
  10.  
  11.     /*-----------------------*/
  12.     public static class OurPresident {
  13.         static {
  14.             synchronized (OurPresident.class) {
  15.                 president = new OurPresident();
  16.             }
  17.         }
  18.  
  19.         private static OurPresident president;
  20.  
  21.         private OurPresident() {
  22.         }
  23.  
  24.         public static OurPresident getOurPresident() {
  25.             return president;
  26.         }
  27.     }
  28.     /*-----------------------------*/
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement