Created
July 3, 2016 21:10
-
-
Save josinSbazin/11d519e93a994e5708d032ee989069dc to your computer and use it in GitHub Desktop.
level17.lesson04.task04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level17.lesson04.task04; | |
/* Синхронизированный президент | |
И снова Singleton паттерн - синхронизация в статическом блоке | |
Внутри класса OurPresident в статическом блоке создайте синхронизированный блок. | |
Внутри синхронизированного блока инициализируйте president. | |
*/ | |
public class Solution { | |
public static class OurPresident { | |
private static OurPresident president; | |
static { | |
synchronized (OurPresident.class) { | |
president = new OurPresident(); | |
} | |
} | |
private OurPresident() { | |
} | |
public static OurPresident getOurPresident() { | |
return president; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment