单例模式的扩展及其应用

上传者: ciwushini | 上传时间: 2021-06-04 20:29:26 | 文件大小: 38KB | 文件类型: RAR
编写一个类LimitInstanceClass,该类最多可以实例化指定个数实例。实例的个数用配置文件InstanceLimit.cfg指定。例如,如果InstanceLimit.cfg的内容为2,则LimitInstanceClass最多可以同时存在2个对象。LimitInstanceClass的对象有一个整型成员变量id,保存对象的编号;有一个boolean型变量isBusy,如果该变量的值为true,表示该对象正在被使用,否则该对象空闲。getInstance()方法判断是否存在空闲的对象,存在将该空闲对象的isBusy置为true,并返回该对象;如果不存在空闲对象则返回null。LimitInstanceClass有一个release()方法,该方法将对象的isBusy置为false。LimitInstanceClass还有一个String类型的成员变量accessMessage,以及一个成员方法writeAccessMessage(String message),该方法将参数message追加到accessMessage。LimitInstanceClass的printAccessMessage()方法输出accessMessage的内容。

文件下载

资源详情

[{"title":"( 18 个子文件 38KB ) 单例模式的扩展及其应用","children":[{"title":"单例模式的扩展及其应用","children":[{"title":".project <span style='color:#111;'> 911B </span>","children":null,"spread":false},{"title":"WebContent","children":[{"title":"WEB-INF","children":[{"title":"lib","children":null,"spread":false}],"spread":true},{"title":"META-INF","children":[{"title":"MANIFEST.MF <span style='color:#111;'> 39B </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":"实验报告.docx <span style='color:#111;'> 34.43KB </span>","children":null,"spread":false},{"title":"src","children":[{"title":"mySingleton","children":[{"title":"AccessLimitInstanceClassThread.java <span style='color:#111;'> 611B </span>","children":null,"spread":false},{"title":"UseLimitInstanceClass.java <span style='color:#111;'> 248B </span>","children":null,"spread":false},{"title":"LimitInstanceClass.java <span style='color:#111;'> 1.29KB </span>","children":null,"spread":false},{"title":"InstanceLimit.cfg <span style='color:#111;'> 1B </span>","children":null,"spread":false}],"spread":true}],"spread":true},{"title":".settings","children":[{"title":"org.eclipse.wst.jsdt.ui.superType.container <span style='color:#111;'> 49B </span>","children":null,"spread":false},{"title":"org.eclipse.wst.common.project.facet.core.xml <span style='color:#111;'> 305B </span>","children":null,"spread":false},{"title":"org.eclipse.jdt.core.prefs <span style='color:#111;'> 364B </span>","children":null,"spread":false},{"title":"org.eclipse.wst.jsdt.ui.superType.name <span style='color:#111;'> 6B </span>","children":null,"spread":false},{"title":"org.eclipse.wst.common.component <span style='color:#111;'> 485B </span>","children":null,"spread":false},{"title":".jsdtscope <span style='color:#111;'> 567B </span>","children":null,"spread":false}],"spread":true},{"title":"build","children":[{"title":"classes","children":[{"title":"mySingleton","children":[{"title":"LimitInstanceClass.class <span style='color:#111;'> 1.90KB </span>","children":null,"spread":false},{"title":"UseLimitInstanceClass.class <span style='color:#111;'> 836B </span>","children":null,"spread":false},{"title":"AccessLimitInstanceClassThread.class <span style='color:#111;'> 1.15KB </span>","children":null,"spread":false},{"title":"InstanceLimit.cfg <span style='color:#111;'> 1B </span>","children":null,"spread":false}],"spread":true}],"spread":true}],"spread":true},{"title":".classpath <span style='color:#111;'> 588B </span>","children":null,"spread":false}],"spread":true}],"spread":true}]

评论信息

  • mckola_molas :
    还可以,没想到几年的代码还可以用,不过我的怎么出了点错了?不过给了思路,已经很好了!谢谢分享!
    2021-06-06
  • qq_37169999 :
    还不错,符合要求。
    2017-12-15

免责申明

【只为小站】的资源来自网友分享,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,【只为小站】 无法对用户传输的作品、信息、内容的权属或合法性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论 【只为小站】 经营者是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。
本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二条之规定,若资源存在侵权或相关问题请联系本站客服人员,zhiweidada#qq.com,请把#换成@,本站将给予最大的支持与配合,做到及时反馈和处理。关于更多版权及免责申明参见 版权及免责申明