From dd455bf16ff2e675addf588f805e5094298d8edc Mon Sep 17 00:00:00 2001 From: CyC2018 <1029579233@qq.com> Date: Sun, 25 Feb 2018 13:53:02 +0800 Subject: [PATCH] auto commit --- notes/剑指 offer 题解.md | 60 +--------------------------------------- notes/设计模式.md | 8 ++++-- 2 files changed, 6 insertions(+), 62 deletions(-) diff --git a/notes/剑指 offer 题解.md b/notes/剑指 offer 题解.md index 51793e1b..97a24945 100644 --- a/notes/剑指 offer 题解.md +++ b/notes/剑指 offer 题解.md @@ -81,65 +81,7 @@ ## 2. ʵ Singleton -**ʵ** - -ʵУ˽о̬ӳٻʵĺôǣûõ࣬ôͲᴴ˽о̬ӶԼԴʵڶ̻߳DzȫģΪܹ߳ͬʱ if(uniqueInstance == null) ڵ飬ôͻʵ uniqueInstance ˽о̬ - -```java -public class Singleton { - private static Singleton uniqueInstance; - private Singleton() { - } - public static Singleton getUniqueInstance() { - if (uniqueInstance == null) { - uniqueInstance = new Singleton(); - } - return uniqueInstance; - } -} -``` - -**̲߳ȫĽһ** - -ֻҪ getUniqueInstance() ø÷һֻһ̷߳ʣӶ˶ uniqueInstance жʵ⡣һһֻһ߳̽룬ϻһ˷ѡ - -```java -public static synchronized Singleton getUniqueInstance() { - if (uniqueInstance == null) { - uniqueInstance = new Singleton(); - } - return uniqueInstance; -} -``` -**̲߳ȫĽ** - -ӳʵֱʵ - -```java -private static Singleton uniqueInstance = new Singleton(); -``` - -**̲߳ȫĽ** - -ǵһֱӶ getUniqueInstance() мʵֻҪ uniqueInstance = new Singleton(); ɡʹж uniqueInstance ǷѾʵûʵҪ - -```java -public class Singleton { - private volatile static Singleton uniqueInstance; - private Singleton() { - } - public static synchronized Singleton getUniqueInstance() { - if (uniqueInstance == null) { - synchronized (Singleton.class) { - if (uniqueInstance == null) { - uniqueInstance = new Singleton(); - } - } - } - return uniqueInstance; - } -} -``` +[ģʽ](https://github.com/CyC2018/InterviewNotes/blob/master/notes/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F.md#%E7%AC%AC-5-%E7%AB%A0-%E5%8D%95%E4%BB%B6%E6%A8%A1%E5%BC%8F) ## 3. ظ diff --git a/notes/设计模式.md b/notes/设计模式.md index c4e44538..ba7d08f5 100644 --- a/notes/设计模式.md +++ b/notes/设计模式.md @@ -491,7 +491,9 @@ CheesePizza **3. ģʽͼ** -ڼ򵥹Уһ࣬ڹУ󡣹ÿ඼ԼһƷࡣΪÿഴļ򵥹ǰѼ򵥹дĴŵԼĿΪ಻DzƷ࣬ȫô +ڼ򵥹Уһ࣬ڹУͼУCreator һ anOperation() ҪõһƷ࣬Ʒÿ + +Ϊÿഴļ򵥹ÿһƷ࣬ǰѼ򵥹дĴŵԼĿΪ಻DzƷ࣬ȫô ![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/903093ec-acc8-4f9b-bf2c-b990b9a5390c.jpg) @@ -599,7 +601,7 @@ ChicagoStyleCheesePizza is making.. **1. ԭ** -**ԭ**Ҫ󣬲ҪࡣԽӿڱ̣ʵֱ̣ԭ˵ˣø߲ײңܸ߲ײ߶Ӧڳ磬ͼ PizzaStore ڸ߲ڵײ Pizza ľࡣ Pizza ij࣬ôͿԲù Pizza ľʵϸڡ +**ԭ**Ҫ󣬲ҪࡣԽӿڱ̣ʵֱ̣ԭ˵ˣø߲ײңܸ߲ײ߶Ӧڳ磬ͼ PizzaStore ڸ߲ Pizza ij࣬ͿԲù Pizza ľʵϸڡ ![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/ddf72ca9-c0be-49d7-ab81-57a99a974c8e.jpg) @@ -792,7 +794,7 @@ public class Singleton { private Singleton() { } - public static synchronized Singleton getUniqueInstance() { + public static Singleton getUniqueInstance() { if (uniqueInstance == null) { synchronized (Singleton.class) { if (uniqueInstance == null) {