当前位置: 首页 > news >正文

网站被收录要怎么做网站购买空间

网站被收录要怎么做,网站购买空间,网站网站制作价格建站网站,wordpress自助申请友链文章目录 一、享元模式定义二、例子2.1 菜鸟教程例子2.1.1 定义被缓存对象2.1.2 定义ShapeFactory 2.2 JDK源码——Integer2.3 JDK源码——DriverManager2.4 Spring源码——HandlerMethodArgumentResolverComposite除此之外BeanFactory获取bean其实也是一种享元模式的应用。 三…

文章目录

  • 一、享元模式定义
  • 二、例子
    • 2.1 菜鸟教程例子
      • 2.1.1 定义被缓存对象
      • 2.1.2 定义ShapeFactory
    • 2.2 JDK源码——Integer
    • 2.3 JDK源码——DriverManager
    • 2.4 Spring源码——HandlerMethodArgumentResolverComposite
    • 除此之外BeanFactory获取bean其实也是一种享元模式的应用。
  • 三、其他设计模式

一、享元模式定义

类型: 结构型模式
介绍: 使用容器(数组、集合等…)缓存常用对象。它也是池技术的重要实现方式,正如常量池、数据库连接池、缓冲池等都是享元模式的应用。
目的: 主要用于减少 频繁创建对象带来的开销。

二、例子

2.1 菜鸟教程例子

2.1.1 定义被缓存对象

public class Circle {private String color;public Circle(String color){this.color = color;     }public void draw() {System.out.println("Circle: Draw()");}
}

2.1.2 定义ShapeFactory

ShapeFactory用HashMap缓存Circle对象。

import java.util.HashMap;public class ShapeFactory {private static final HashMap<String, Shape> circleMap = new HashMap<>();public static Shape getCircle(String color) {Circle circle = (Circle)circleMap.get(color);if(circle == null) {circle = new Circle(color);circleMap.put(color, circle);System.out.println("Creating circle of color : " + color);}return circle;}
}

2.2 JDK源码——Integer

-128~127会去IntegerCache里获取

public final class Integer extends Number implements Comparable<Integer>, Constable, ConstantDesc {@IntrinsicCandidatepublic static Integer valueOf(int i) {if (i >= IntegerCache.low && i <= IntegerCache.high)return IntegerCache.cache[i + (-IntegerCache.low)];return new Integer(i);}}

缓存池IntegerCache

private static class IntegerCache {static final int low = -128;static final int high;static final Integer[] cache;static Integer[] archivedCache;static {// high value may be configured by propertyint h = 127;String integerCacheHighPropValue =VM.getSavedProperty("java.lang.Integer.IntegerCache.high");if (integerCacheHighPropValue != null) {try {h = Math.max(parseInt(integerCacheHighPropValue), 127);// Maximum array size is Integer.MAX_VALUEh = Math.min(h, Integer.MAX_VALUE - (-low) -1);} catch( NumberFormatException nfe) {// If the property cannot be parsed into an int, ignore it.}}high = h;// Load IntegerCache.archivedCache from archive, if possibleCDS.initializeFromArchive(IntegerCache.class);int size = (high - low) + 1;// Use the archived cache if it exists and is large enoughif (archivedCache == null || size > archivedCache.length) {Integer[] c = new Integer[size];int j = low;for(int i = 0; i < c.length; i++) {c[i] = new Integer(j++);}archivedCache = c;}cache = archivedCache;// range [-128, 127] must be interned (JLS7 5.1.7)assert IntegerCache.high >= 127;}private IntegerCache() {}
}

2.3 JDK源码——DriverManager

CopyOnWriteArrayList registeredDrivers 缓存DriverInfo对象。

public class DriverManager {// List of registered JDBC driversprivate static final CopyOnWriteArrayList<DriverInfo> registeredDrivers = new CopyOnWriteArrayList<>();public static Connection getConnection(String url, java.util.Properties info) throws SQLException {return (getConnection(url, info, Reflection.getCallerClass()));}@CallerSensitiveAdapterprivate static Connection getConnection(String url, java.util.Properties info, Class<?> caller) throws SQLException {/** When callerCl is null, we should check the application's* (which is invoking this class indirectly)* classloader, so that the JDBC driver class outside rt.jar* can be loaded from here.*/ClassLoader callerCL = caller != null ? caller.getClassLoader() : null;if (callerCL == null || callerCL == ClassLoader.getPlatformClassLoader()) {callerCL = Thread.currentThread().getContextClassLoader();}if (url == null) {throw new SQLException("The url cannot be null", "08001");}println("DriverManager.getConnection(\"" + url + "\")");ensureDriversInitialized();// Walk through the loaded registeredDrivers attempting to make a connection.// Remember the first exception that gets raised so we can reraise it.SQLException reason = null;for (DriverInfo aDriver : registeredDrivers) {// If the caller does not have permission to load the driver then// skip it.if (isDriverAllowed(aDriver.driver, callerCL)) {try {println("    trying " + aDriver.driver.getClass().getName());Connection con = aDriver.driver.connect(url, info);if (con != null) {// Success!println("getConnection returning " + aDriver.driver.getClass().getName());return (con);}} catch (SQLException ex) {if (reason == null) {reason = ex;}}} else {println("    skipping: " + aDriver.driver.getClass().getName());}}// if we got here nobody could connect.if (reason != null)    {println("getConnection failed: " + reason);throw reason;}println("getConnection: no suitable driver found for "+ url);throw new SQLException("No suitable driver found for "+ url, "08001");}}

2.4 Spring源码——HandlerMethodArgumentResolverComposite

public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgumentResolver {private final List<HandlerMethodArgumentResolver> argumentResolvers = new LinkedList<>();private final Map<MethodParameter, HandlerMethodArgumentResolver> argumentResolverCache = new ConcurrentHashMap<>(256);@Nullableprivate HandlerMethodArgumentResolver getArgumentResolver(MethodParameter parameter) {HandlerMethodArgumentResolver result = (HandlerMethodArgumentResolver)this.argumentResolverCache.get(parameter);if (result == null) {Iterator var3 = this.argumentResolvers.iterator();while(var3.hasNext()) {HandlerMethodArgumentResolver resolver = (HandlerMethodArgumentResolver)var3.next();if (resolver.supportsParameter(parameter)) {result = resolver;this.argumentResolverCache.put(parameter, resolver);break;}}}return result;}
}

除此之外BeanFactory获取bean其实也是一种享元模式的应用。

三、其他设计模式

创建型模式
结构型模式

  • 1、设计模式——装饰器模式(Decorator Pattern)+ Spring相关源码

行为型模式

  • 1、设计模式——访问者模式(Visitor Pattern)+ Spring相关源码
  • 2、设计模式——中介者模式(Mediator Pattern)+ JDK相关源码
  • 3、设计模式——策略模式(Strategy Pattern)+ Spring相关源码
  • 4、设计模式——状态模式(State Pattern)
  • 5、设计模式——命令模式(Command Pattern)+ Spring相关源码
  • 6、设计模式——观察者模式(Observer Pattern)+ Spring相关源码
  • 7、设计模式——备忘录模式(Memento Pattern)
  • 8、设计模式——模板方法模式(Template Pattern)+ Spring相关源码
  • 9、设计模式——迭代器模式(Iterator Pattern)+ Spring相关源码
  • 10、设计模式——责任链模式(Chain of Responsibility Pattern)+ Spring相关源码
  • 11、设计模式——解释器模式(Interpreter Pattern)+ Spring相关源码
http://www.yayakq.cn/news/762285/

相关文章:

  • 网站编辑的工作内容自媒体123网站
  • 企业网站建设图手机网站怎样做
  • 永泰建设工程网站美食网站的设计与实现
  • 抚州建设局网站推广方案万能模板
  • 代写网站公司网站域名过期
  • 网站设计 西安唐山网站制作案例
  • 在菲律宾做网站推广怎么样苏州建站公司精选苏州聚尚网络
  • wordpress好用的会员2020 惠州seo服务
  • 怎么仿网站链接雨花区师德师风建设专题网站
  • 门户网站建设的步骤南昌做网站的公司多不多
  • 比较流行的网站建设技术有哪些广州网站建设哪家强
  • 网站以下内容未做缓存网站开发交流群
  • 设计师个人作品集网站美团这个网站多少钱做的
  • 了解网站的建设心得河南网站备案系统短信
  • 弥勒网站设计公司加强纪检监察网站建设
  • 如何知道网站是否被k做海报图片去哪个网站找 知乎
  • 网站优化推广怎么做权威的网站建设排行榜
  • 企业的网站建设文章做全国社保代理的网站
  • 网站建设的流程是什么衣服网站建设方案书
  • 做网站放广告赚钱用eclipse做网站
  • 保定网站制作哪家好建设云恒网站建设公司
  • 欧美男女直接做的视频网站怎么创办个人网站
  • 网站建设字体颜色代码南京搜必应网站优化
  • 化妆品网站模板免费下载江山建设工程信息网站
  • 网站制作企业对比苏州区网站建设
  • wordpress需要的环境哈尔滨seo建站
  • wordpress 网站标题图网站com域名上不去cn能
  • 企业门户网站建设案例网站建设全部代码
  • 专做水果的社区网站网站的二级页面在哪里做
  • 关于建设工程的网站律师个人网站建设