Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level17.lesson04.task04;
- /* Синхронизированный президент
- И снова Singleton паттерн - синхронизация в статическом блоке
- Внутри класса OurPresident в статическом блоке создайте синхронизированный блок.
- Внутри синхронизированного блока инициализируйте president.
- */
- public class Solution {
- /*-----------------------*/
- public static class OurPresident {
- static {
- synchronized (OurPresident.class) {
- president = new OurPresident();
- }
- }
- private static OurPresident president;
- private OurPresident() {
- }
- public static OurPresident getOurPresident() {
- return president;
- }
- }
- /*-----------------------------*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement