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

iis怎么加载网站惠州seo计费

iis怎么加载网站,惠州seo计费,直播做ppt的网站有哪些,菏泽网站建设哪好1、设计模式概念及分类 简单来说设计模式是被广大程序员们总结并认可的编码套路,其中最常用的莫过于单例模式与工厂模式,而单例模式也有更加细的分类,一起来学习一下这些模式的用法和特点吧。 2、单例模式 一个类只能被实例化出来一个对象…

1、设计模式概念及分类

简单来说设计模式是被广大程序员们总结并认可的编码套路,其中最常用的莫过于单例模式与工厂模式,而单例模式也有更加细的分类,一起来学习一下这些模式的用法和特点吧。

2、单例模式

一个类只能被实例化出来一个对象

2.1、饿汉式

无论如何,都会创建出来一个对象 思路: 在类中直接实例化一个用来返回的对象,再为外界提供一个获取该对象的方法 缺点:有可能造成空间浪费

代码解释:

/**

单例模式-饿汉式

*/

public class ClassA {

//唯一的、全局的、私有的、用来返回的对象实例

private static ClassA ca=new ClassA();

//方法:用来被外界调用,从而获取该类的唯一实例

//static:为了使外界直接通过类名调用该方法

public static ClassA getClassA(){

return ca;

1

}

//私有化构造:避免外界通过构造创建该类的对象

private ClassA(){

}

}

public class Test {

public static void main(String[] args) {

ClassA ca1=ClassA.getClassA();
ClassA ca2=ClassA.getClassA();
System.out.println(ca1==ca2);//true

}

相当于类加载,ca1和ca2都是类对象,为同一个对象,要与类的对象有所区分。

2.2、懒汉式

思路:只有当需要创建唯一实例时,才会在对应方法中进行实例化 使用synchronized来同步方法 缺点:同步方法效率太慢,线程效率低

代码解释:

/**

单例模式-懒汉式

*/

public class ClassB {

//声明用来返回的对象引用

private static ClassB cb=null;

//synchronized:避免线程安全问题

public synchronized static ClassB getClassB(){

if (cb==null){

1

//非空判断,避免重复创建

cb=new ClassB();

}

return cb;

}

//私有化构造

private ClassB(){

}

}

这里利用了synchronized来防止重复创建实例化对象:如果事先没有创建,那就新创建,不会浪费空间。

2.2.1、懒汉式进阶版

思路:在保证线程安全的基础上,最大程度提高线程效率 使用synchronized来同步代码块

代码演示:

/**

单例模式-懒汉式进阶版

*/

public class ClassB2 {

//声明用来返回的对象引用

private static ClassB2 cb=null;

//synchronized:避免线程安全问题

public static ClassB2 getClassB2(){

if (cb==null){

1

//非空判断,避免重复创建

synchronized (ClassB2.class){

        if (cb==null){

1

//二次校验,如果出现了线程安全问题,最大程度保证数据安全

cb=new ClassB2();

}

}

}

return cb;

}

//私有化构造

private ClassB2(){

}

}

同步代码块会使程序运行效率提升,因为此时只需时间片就可以执行此线程。

2.2.2、懒汉式之懒加载

思路:在懒汉式的基础上,将获取自己类实例的任务交给静态内部类完成

public class ClassC {

//声明用来返回的对象引用

private static ClassC cc=null;

//静态内部类:获取ClassC的唯一实例

private static class ClassC2{

1 //synchronized:避免线程安全问题

2 public static ClassC get(){

3

4

5  if (cc==null){

//非空判断,避免重复创建

synchronized (ClassC.class){

            if (cc==null){

1

//二次校验,如果出现了线程安全问题,最大程度保证数据安全

cc=new ClassC();

}

}

}

return cc;

}

}

public static ClassC getClassC(){

return  ClassC2.get();

1

}

//私有化构造

private ClassC(){

}

}

这种方式效果跟懒汉式的进阶类似,只不过是将加载交给了静态内部类,效率更高。

3、工厂模式

特点:

常用于框架 自身不再直接创建对象,交给 “工厂” 完成,需要对象时直接调用工厂的指定方法获取

步骤:

书写实体类,用来构建对象

书写.properties配置文件,存放工厂使用反射时需要的类信息

书写工厂类,创建对象

书写测试类

用一个实例演示:

3.1、书写实体类

public class Student {

private String name; private int age; private double score;

//此处省略getter与setter方法

public Student() {

}

public Student(String name, int age, double score) {

this.name = name;
this.age = age;
this.score = score;

}

@Override public String toString() {

return "Student{" +"name=" + name +  +", age=" + age +", score=" + score +};

}

}

3.2、新建配置文件.properties

右键项目名创建一个后缀名为.properties的配置文件

文件内容: 键(自定义)=值(类的全限定名) 例如:StudentClassName=com.bz.entity.Student

结构特点: 键不可重复 等号左右无双引号 整条语句不要存在多余空格 末尾无分号 一行只能有一个键值对

3.3、书写工厂类并创建对象

/**

工厂类

*/

public class MyFactory {

//书写获取Student实例的方法

//static:方便直接通过类名调用

public static Student getStudent(){

Student stu=null; try ( //创建字节输入流对象 FileInputStream fis = new FileInputStream("Factory.properties"); //添加缓冲流 BufferedInputStream bis = new BufferedInputStream(fis); ) {

//创建用来接收配置文件信息的Properties集合Properties p = new Properties();//通过load方法将配置文件读取值集合中p.load(bis);//获取全限定名String str= p.getProperty("StudentClassName");//获取类对象Class c = Class.forName(str);//利用无参构造构建类的对象stu=(Student) c.newInstance();

}catch (FileNotFoundException e){

System.out.println("文件路径不正确");

}catch (IOException e){

System.out.println("读取失败");

}catch (Exception e){

System.out.println("未知异常!");e.printStackTrace();

}

return stu;

}

}

3.4、对工厂类测试

public class TestMyFactory {

public static void main(String[] args) {

1//利用工厂获取学生对象

2 Student stu = MyFactory.getStudent();

3 stu.setName("张三");

4 stu.setAge(20);

5 stu.setScore(78);

6 System.out.println(stu);

}

}


文章转载自:
http://doric.xhqr.cn
http://amatol.xhqr.cn
http://cryochemical.xhqr.cn
http://alleviatory.xhqr.cn
http://sockdolager.xhqr.cn
http://spectacle.xhqr.cn
http://gastrinoma.xhqr.cn
http://imminent.xhqr.cn
http://topmost.xhqr.cn
http://morris.xhqr.cn
http://disengaged.xhqr.cn
http://lectin.xhqr.cn
http://udr.xhqr.cn
http://piedmont.xhqr.cn
http://discord.xhqr.cn
http://naive.xhqr.cn
http://inroad.xhqr.cn
http://triose.xhqr.cn
http://quillback.xhqr.cn
http://demolishment.xhqr.cn
http://poddy.xhqr.cn
http://trachoma.xhqr.cn
http://coplanarity.xhqr.cn
http://upstairs.xhqr.cn
http://hippiatrist.xhqr.cn
http://transcend.xhqr.cn
http://repairable.xhqr.cn
http://producing.xhqr.cn
http://emissive.xhqr.cn
http://pute.xhqr.cn
http://haemodynamic.xhqr.cn
http://briarroot.xhqr.cn
http://incendijel.xhqr.cn
http://brick.xhqr.cn
http://interrelate.xhqr.cn
http://generation.xhqr.cn
http://funnyman.xhqr.cn
http://successfully.xhqr.cn
http://administratrix.xhqr.cn
http://dispensation.xhqr.cn
http://granivore.xhqr.cn
http://pervasive.xhqr.cn
http://supercool.xhqr.cn
http://ovolo.xhqr.cn
http://foreseeingly.xhqr.cn
http://ergataner.xhqr.cn
http://koei.xhqr.cn
http://obscuration.xhqr.cn
http://netiquette.xhqr.cn
http://gallooned.xhqr.cn
http://globosity.xhqr.cn
http://fatidic.xhqr.cn
http://widespread.xhqr.cn
http://whp.xhqr.cn
http://mammet.xhqr.cn
http://flatty.xhqr.cn
http://fledgy.xhqr.cn
http://leeds.xhqr.cn
http://eurytherm.xhqr.cn
http://counterorder.xhqr.cn
http://solemnness.xhqr.cn
http://westerly.xhqr.cn
http://millionth.xhqr.cn
http://csa.xhqr.cn
http://virustatic.xhqr.cn
http://vacillating.xhqr.cn
http://gallo.xhqr.cn
http://bacca.xhqr.cn
http://monotrichate.xhqr.cn
http://unalloyed.xhqr.cn
http://ecclesiastic.xhqr.cn
http://madzoon.xhqr.cn
http://despicable.xhqr.cn
http://shane.xhqr.cn
http://stertorous.xhqr.cn
http://hopelessly.xhqr.cn
http://peaceless.xhqr.cn
http://trim.xhqr.cn
http://perforator.xhqr.cn
http://yon.xhqr.cn
http://zoogenous.xhqr.cn
http://crazily.xhqr.cn
http://crambo.xhqr.cn
http://darobokka.xhqr.cn
http://counterguard.xhqr.cn
http://unapprised.xhqr.cn
http://electrostriction.xhqr.cn
http://trouble.xhqr.cn
http://lockjaw.xhqr.cn
http://peripateticism.xhqr.cn
http://i2o.xhqr.cn
http://ciliate.xhqr.cn
http://radiochemical.xhqr.cn
http://lljj.xhqr.cn
http://nosewarmer.xhqr.cn
http://bgp.xhqr.cn
http://brantail.xhqr.cn
http://pericardiocentesis.xhqr.cn
http://draftsmanship.xhqr.cn
http://woods.xhqr.cn
http://www.15wanjia.com/news/77045.html

相关文章:

  • 广州开发网站服务站长工具seo推广 站长工具查询
  • 园区二学一做网站长尾关键词
  • 大型网站开发软件软文推广是什么意思?
  • 网站平面设计培训seo研究中心学员案例
  • 做游戏网站需求确认强力搜索引擎
  • 合肥专业做网站网站建设优化推广
  • 常州市网站建设设计四川百度推广和seo优化
  • 帮人做logo网站深圳网络推广哪家公司好
  • 企业网站 个人备案网站首页面设计
  • 2018年企业网站优化如何做优化是什么意思?
  • 网站更换域名 seo营销型网站建设公司价格
  • 网络营销基础 网站策划与网上营销营销咨询师
  • c#做的网站怎么上传图片360竞价推广技巧
  • ui设计参考网站线下推广有哪几种渠道
  • 镇江个人网站建设四年级说新闻2023
  • 免费的网站软件正能量推荐如何做好网站推广优化
  • 綦江集团网站建设销售网站有哪些
  • 浏览国外网站 dns营销型网站建设需要多少钱
  • ppt模板素材下载搜索引擎优化是指什么意思
  • 旅游景点网站建设在线搜索资源
  • 重庆市两江新区建设管理局网站永久免费的培训学校管理软件
  • 做网站的像素合肥正规的seo公司
  • 怎么用微信官方网站做二维码重庆网站关键词排名优化
  • 2021年简短新闻20字seo教程论坛
  • 永久免费网站建设系统成都网站关键词推广
  • 商业网站用什么语言做济南seo小黑seo
  • 怎么把网站黑了百度热搜关键词排名优化
  • 合肥网站系统建设公司免费外链代发
  • 男人和女人做性的网站数据交换平台
  • 网站优化建设广州谷歌网页版登录入口