问题 Description //DVDPlayer.java public class DVDPlayer { private static DVDPlayer instance = new DVDPlayer(); public static DVDPlayer getInstance(){ r ...
分类:
其他好文 时间:
2020-06-27 20:21:00
阅读次数:
75
单例模式保证一个类仅有一个实例,并提供一个访问它的全局访问点。这是个非常有意思的设计模式,使用和理解起来都比较简单,但是单例的写法有好多种,下面挑重点的介绍。 1、饿汉式 public class Singleton1 { private static final Singleton1 INSTAN ...
分类:
其他好文 时间:
2020-06-27 15:55:37
阅读次数:
50
这个模式很简单,直接上代码: public class Singleton { private static Singleton uniqueInstance; private Singleton() {}; public static Singleton getInstance() { if(un ...
分类:
其他好文 时间:
2020-06-27 11:42:55
阅读次数:
50
前言 我们都知道memberwiseclone 会将浅克隆。 什么是浅克隆?如何深克隆呢? 正文 public class good{ private good(){ oneclass=new class{ int id=8; string name='id'; } } private static ...
public static void main(String []f) { try { test(); } catch (Exception e) { e.printStackTrace(); } } private static void test() { try { int i = 1 / 0; ...
分类:
其他好文 时间:
2020-06-26 16:44:05
阅读次数:
65
wait/notify机制: import java.util.ArrayList; import java.util.List; public class MyList { private static List<String> list = new ArrayList<String>(); pu ...
分类:
编程语言 时间:
2020-06-24 23:50:51
阅读次数:
73
1 import java.util.*; 2 3 public class Main { 4 private static boolean match(String matchStr, String str, int matchIdx, int idx) { 5 if (matchIdx == m ...
分类:
其他好文 时间:
2020-06-24 23:23:44
阅读次数:
57
说明 代码剥离自其他老哥的项目,项目地址——https://github.com/wangzaiplus/springboot/tree/wxw 再此记录下来以备不时之需 创建注解 /** * 在需要保证 接口防刷限流 的Controller的方法上使用此注解 */ @Target({Element ...
分类:
编程语言 时间:
2020-06-24 15:50:02
阅读次数:
55
1、单例设计 class Singleton{ private static final Singleton SINGLETON =new Singleton(); public static Singleton getSingleton(){ return SINGLETON; } private ...
分类:
编程语言 时间:
2020-06-24 12:21:39
阅读次数:
61
直接上代码去跑发现其中的规律即可 public class ThreadPollUtil { private static int corePoolSize = Runtime.getRuntime().availableProcessors(); /** * corePoolSize 用于指定核心 ...
分类:
编程语言 时间:
2020-06-23 15:17:48
阅读次数:
61