Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Test02.java #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Test02.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* Author: ������
* Author: 王俊超
* Date: 2015-04-21
* Time: 13:58
* Declaration: All Rights Reserved !!!
*/
public class Test02 {

/**
* ����ģʽ������ʽ���̰߳�ȫ
* 单例模式,饿汉式,线程安全
*/
public static class Singleton {
private final static Singleton INSTANCE = new Singleton();
Expand All @@ -22,7 +22,7 @@ public static Singleton getInstance() {
}

/**
* ����ģʽ������ʽ���̲߳���ȫ
* 单例模式,懒汉式,线程不安全
*/
public static class Singleton2 {
private static Singleton2 instance = null;
Expand All @@ -42,7 +42,7 @@ public static Singleton2 getInstance() {


/**
* ����ģʽ������ʽ���̰߳�ȫ�����̻߳�����Ч�ʲ���
* 单例模式,懒汉式,线程安全,多线程环境下效率不高
*/
public static class Singleton3 {
private static Singleton3 instance = null;
Expand All @@ -61,7 +61,7 @@ public static synchronized Singleton3 getInstance() {
}

/**
* ����ģʽ������ʽ�����֣��̰߳�ȫ
* 单例模式,懒汉式,变种,线程安全
*/
public static class Singleton4 {
private static Singleton4 instance = null;
Expand All @@ -80,7 +80,7 @@ public static Singleton4 getInstance() {
}

/**
* ����ģʽ������ʽ��ʹ�þ�̬�ڲ��࣬�̰߳�ȫ���Ƽ���
* 单例模式,饿汉式,使用静态内部类,线程安全【推荐】
*/
public static class Singleton5 {
private final static class SingletonHolder {
Expand All @@ -97,7 +97,7 @@ public static Singleton5 getInstance() {
}

/**
* ��̬�ڲ��࣬ʹ��ö�ٷ�ʽ���̰߳�ȫ���Ƽ���
* 静态内部类,使用枚举方式,线程安全【推荐】
*/
public enum Singleton6 {
INSTANCE;
Expand All @@ -108,7 +108,7 @@ public void whateverMethod() {
}

/**
* ��̬�ڲ��࣬ʹ��˫��У�������̰߳�ȫ���Ƽ���
* 静态内部类,使用双重校验锁,线程安全【推荐】
*/
public static class Singleton7 {
private volatile static Singleton7 instance = null;
Expand Down