From 5503d2fcddb1727fd70d1d63ddebbc81fe91ea89 Mon Sep 17 00:00:00 2001 From: niaonao Date: Mon, 8 Jun 2020 14:02:28 +0800 Subject: [PATCH] add Everything i want is yours. --- "\343\200\202java" | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 "\343\200\202java" diff --git "a/\343\200\202java" "b/\343\200\202java" new file mode 100644 index 0000000..6166072 --- /dev/null +++ "b/\343\200\202java" @@ -0,0 +1,33 @@ +/** + * @className: GirlFriendSingleton + * @description: Love a person and live to death + **/ +@Slf4j +public class GirlFriendSingleton { + + // Often miss you through time and space + volatile private static GirlFriendSingleton girlFriend = null; + + private GirlFriendSingleton(){ + } + + public static GirlFriendSingleton getInstance() { + try { + // My love, Where are you + if(null == girlFriend){ + Thread.sleep(300); + // Everything i want is yours + synchronized (GirlFriendSingleton.class) { + // Only U, and it must be U + if(null == girlFriend){ + girlFriend = new GirlFriendSingleton(); + } + } + } + } catch (InterruptedException e) { + // Love a person and live to death + log.error(e.getMessage()); + } + return girlFriend; + } +} \ No newline at end of file -- Gitee