单例模式的特点

=============================== 定义单例模式 单例模式特点: •一个类Class只有一个实例存在。 •使用Singleton的好处还在于可以节省内存,因为它限制了实例的个数,有利于Java垃圾回收(garbage collection)。 单例模式操作步骤 //提供私有SqlSessionFactory类静态属性供外界访问的共有方法 public static SqlSessionFactory getSqlSessionFactory() { if (sf == null) { InputStream in = SqlSessionFactoryUtil.class.getResourceAsStream("MyBatisConfiguration.xml"); sf=new SqlSessionFactoryBuilder().build(in); } returnsf; }
posted @ 2018-08-20 11:17  砥砺奋进的几年  阅读(560)  评论(0编辑  收藏  举报