GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Create 单例设计模式.MD · WhCannon/JavaSE@52bc3e3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Design-pattern
    • 单例设计模式.MD
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Design-pattern/单例设计模式.MD‎

Copy file name to clipboard
+27Lines changed: 27 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### 饿汉式(无安全隐患)
2+
```java
3+
class Single
4+
{
5+
private static final Single s = new Single();
6+
private Single(){}
7+
public static Single getInstance()
8+
{
9+
return s;
10+
}
11+
}
12+
```
13+
14+
### 懒汉式-延迟加载形式(多线程下存在安全隐患)
15+
```java
16+
class Single
17+
{
18+
private static Single s = null;
19+
private Single(){}
20+
public static Single getInstance()
21+
{
22+
if(s==null)
23+
s = new Single();
24+
return s;
25+
}
26+
}
27+
```

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.