关于javascript:手摸手带你用Hexo撸博客二之配置主题

3次阅读

共计 11431 个字符,预计需要花费 29 分钟才能阅读完成。

// 测试 Singleton instance = Singleton.getInstance();
Singleton instance1 = Singleton.getInstance();System.out.println(instance == instance1);//true
System.out.println(“instance.hashCode=” + instance.hashCode());//1163157884System.out.println(“instance1.hashCode=” + instance1.hashCode());//1163157884
}}
// 饿汉式 (动态变量)
class Singleton {//1. 私有化结构器,内部不能能 new
private Singleton() {}//2. 在本类外部创建对象实例
private final static Singleton instance = new Singleton();//3. 提供一个共有的静态方法,返回实例对象
public static Singleton getInstance() {return instance;
}}
优缺点阐明长处;这种写法比较简单,就是再类装载的时候就实现实例化。防止了线程同步问题。
毛病;再类装载的时候就实现实例化,没有达到 Lazy Loading(懒加载)的成果。如果从始至终从未应用这个实例,则会造成内存的节约。这种办法基于 classloder 机制防止了多线程的同步问题,不过,instance 再类装载时就实例化,再单例模式种大多数都是调用 getInstance 办法,然而导致类装载的起因有很多种,因而不能确定其余的形式 (或者其余的静态方法) 导致类装载,这时候初始化 instance 就没有达到 lazy loading 的成果
论断;这种单例模式可用,可能造成内存节约。饿汉式 (动态代码块)
代码
public class SingletonTest2 {
public static void main(String[] args) {// 测试
Singleton instance = Singleton.getInstance();Singleton instance1 = Singleton.getInstance();
System.out.println(instance == instance1);//trueSystem.out.println(“instance.hashCode=” + instance.hashCode());//1163157884
System.out.println(“instance1.hashCode=” + instance1.hashCode());//1163157884}
}
// 饿汉式(动态变量)class Singleton {
//1. 私有化结构器,内部不能能 newprivate Singleton() {}
//2. 在本类外部创建对象实例 private static Singleton instance;
// 在动态代码块中,创建对象 static {instance = new Singleton(); }
//3. 提供一个共有的静态方法,返回实例对象 public static Singleton getInstance() {
return instance;}
} 优缺点阐明
这种形式和下面的形式其实相似,只不过将类实例的过程放在了动态代码块中,也是再类装载的时候,就执行动态代码块中的代码,初始化类的实例。优缺点和下面是一样的。
论断;这种单例模式可用,然而可能造成内存节约。懒汉式 (线程不平安)
代码
public class SingletonTest03 {
public static void main(String[] args) {// 测试
System.out.println(“ 懒汉式 1,线程不平安 ”);Singleton instance = Singleton.getInstance();
Singleton instance1 = Singleton.getInstance();System.out.println(instance == instance1);//true
System.out.println(“instance.hashCode=” + instance.hashCode());//1163157884System.out.println(“instance1.hashCode=” + instance1.hashCode());//1163157884
}}
class Singleton {
private static Singleton instance;public Singleton() {}
// 提供一个动态的共有办法,当应用该办法时,才去创立 instance// 即懒汉式
public static Singleton getInstance() {if (instance == null) {
instance = new Singleton();}
return instance;}
} 长处阐明
起到 Lazy Loading 的成果,然而只能再单线程下应用。
如果再多线程下,一个线程进入 if(singlenton == null) 判断语句块,还未来得及往下执行,另一个线程也通过这个判断语句,这是便会差生多个实例。所以再多线程环境下不可应用这种形式。论断:再理论开发中,不要应用这种形式。
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…://github.com/threebb10/wnkjpyqzbs/discussions/262
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…://www.github.com/threebb10/wnkjpyqzbs/discussions/270
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
https://github.com/threebb10/…
https://www.github.com/threeb…
http://github.com/threebb10/w…
懒汉式(线程平安,同步办法)

代码

class Singleton{
private static Singleton singlenton;

正文完
 0