package singeton;

import java.security.SecureRandom;

/**
* @author Zero
* @since 2019-08-13.
* Description:
*/
public class HungrySingleton {
private static final HungrySingleton singleton = new HungrySingleton();
private final int ID = new SecureRandom().nextInt(); private HungrySingleton() {
} public static HungrySingleton getSingleton() {
return singleton;
} public int doSomething() {
// System.out.println("I'm HungrySingeton " + ID + "!");
return ID;
}
}
package singeton;

import java.security.SecureRandom;

/**
* @author Zero
* @since 2019-08-13.
* Description:
*/
public class LazySingleton {
private static LazySingleton singeton = null;
private final int ID = new SecureRandom().nextInt(); private LazySingleton() {
} public static synchronized LazySingleton getSingleton() {
if (singeton == null) {
singeton = new LazySingleton();
}
return singeton;
} public int doSomething() {
// System.out.println("I'm LazySingeton " + ID + "!");
return ID;
} }

最新文章

  1. MySQL 5.7 学习:新增配置参数
  2. 网络热恋之XML解析
  3. [转]AndroidManifest.xml文件详解
  4. Mac下获取AppStore安装包文件路径
  5. JavaScript设计模式之策略模式(学习笔记)
  6. HDOJ 4248 A Famous Stone Collector DP
  7. stm32之keil开发环境搭建
  8. Hbase思维导图之数据存储
  9. 在已有的Java项目中使用Kotlin
  10. C#中使用Application.AddMessageFilter(this)要手动释放
  11. 【微服务系列】Spring SpringMVC SpringBoot SpringCloud概念、关系及区别
  12. 抓取错误之onerror
  13. spring eureka required a bean of type 'com.netflix.discovery.DiscoveryClient' that could not be found.
  14. 1084 Broken Keyboard (20 分)
  15. SDOI 2017 天才黑客
  16. Bash:常用命令工具-tr命令
  17. Python全栈开发之15、DOM
  18. 转CentOS — MySQL备份 Shell 脚本
  19. windows7系统PC机耳机没有声音
  20. 省市联动js代码

热门文章

  1. 4sql
  2. 经典sql面试题(学生表_课程表_成绩表_教师表)
  3. 【并发编程】Object的wait、notify和notifyAll方法
  4. Tensorflow搭建CNN实现验证码识别
  5. 为啥HashMap的默认容量是16?
  6. unity3D 游戏物体同时绑定单击、双击事件
  7. Semaphore回顾
  8. SpringBoot-多环境切换相关(六)
  9. 针对tomcat中startup启动服务器闪退的情况
  10. [TimLinux] JavaScript AJAX如何重定向页面