AtomicInteger类的理解与使用 首先看两段代码,一段是Integer的,一段是AtomicInteger的,为以下: public class Sample1 { private static Integer count = 0; synchronized public static vo ...
分类:
其他好文 时间:
2020-04-13 12:30:45
阅读次数:
65
首先我们还是拿饿汉模式作为栗子进行测试,饿汉模式的代码如下: public class HungrySingleton implements Serializable { private static final HungrySingleton instance; static { instance ...
分类:
其他好文 时间:
2020-04-10 21:15:18
阅读次数:
106
/** * @des 一个数的最小因子的连乘 * 2*2*2*2*2*2*5*5*5*5*5*5*=1000000 * @param a */ private static void min(int a) { int b =a; StringBuilder stringBuilder = new S ...
分类:
其他好文 时间:
2020-04-05 15:28:33
阅读次数:
113
#懒汉式,线程安全 public class Singleton{ private static Singleton instance; private Singleton(){} public static synchronized Singleton getInstance(){ if (ins ...
分类:
其他好文 时间:
2020-04-04 22:56:20
阅读次数:
70
1 private static int SOCKET_TIME_OUT = 60*1000; //传输间隔超时 2 private static int CONNECT_TIME_OUT = 60*1000; //链接建立超时 3 4 /** 5 * @author Yanzm 6 * @para ...
分类:
Web程序 时间:
2020-04-04 00:07:06
阅读次数:
83
private static final String DEFAULT_PATH = "D:\\default_path"; private static final String DEFAULT_NAME = "default_name.txt"; public static void write ...
分类:
其他好文 时间:
2020-04-03 23:46:45
阅读次数:
85
private static TransportClient client = ElasticSearch.getClientSingle();BulkRequestBuilder bulkRequestBuilder = client.prepareBulk(); List<Map<String, ...
分类:
编程语言 时间:
2020-04-03 12:21:03
阅读次数:
79
1. 饿汉式: 类静态变量,利用类的初始化,jvm 中一个class 只会初始化一次 public class A{ public static final A a= new A(); } 2. 懒汉式 public class A{ private static A a; public synch ...
分类:
编程语言 时间:
2020-04-03 12:13:53
阅读次数:
71
User.java public class User { private static int a = 10; { System.out.println("普通代码块.."); } static { System.out.println("静态变量" + a); System.out.printl ...
分类:
其他好文 时间:
2020-04-01 14:45:11
阅读次数:
100
直接上代码: 1、定义静态方法 import com.alibaba.fastjson.JSON; public class MessageUtils implements Cloneable { private static final MessageUtils instance = new Me ...
分类:
编程语言 时间:
2020-04-01 11:17:47
阅读次数:
249