[logseq-plugin-git:commit] 2024-07-01T05:24:58.263Z
This commit is contained in:
@@ -14,7 +14,44 @@
|
||||
- 调用的时间是不确定的
|
||||
- 手写单例模式 #card #java
|
||||
id:: 66820808-c5d5-4c44-a5f3-f6273725469d
|
||||
-
|
||||
- 饿汉式
|
||||
- ```java
|
||||
public class Singleton {
|
||||
private static Singleton instance = new Singleton()
|
||||
private Singleton() {}
|
||||
public static Singlton getSingleton() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
```
|
||||
- 懒汉式
|
||||
- ```java
|
||||
public class Singleton {
|
||||
private static Singleton singleton;
|
||||
private Singleton() {}
|
||||
public synchronized static Singlton getSingleton() {
|
||||
if (singleton == null) {
|
||||
singleton = new Singleton();
|
||||
}
|
||||
return singleton;
|
||||
}
|
||||
}
|
||||
|
||||
public class Singleton {
|
||||
private volatile static Singleton singleton;
|
||||
private Singleton() {}
|
||||
public static Singlton getSingleton() {
|
||||
if (singleton == null) {
|
||||
synchronized (Singlton.class) {
|
||||
if (singleton == null) {
|
||||
singleton = new Singleton();
|
||||
}
|
||||
}
|
||||
}
|
||||
return singleton;
|
||||
}
|
||||
}
|
||||
```
|
||||
- 用了redis哪些数据结构 #card #java
|
||||
id:: 66820850-48cc-4bde-8ec6-8ca8ce5d42e0
|
||||
- string,存验证码,缓存常用的一些数据
|
||||
|
||||
Reference in New Issue
Block a user