用enum枚举类实现单例模式
来源:互联网 发布:电子版世界名画淘宝店 编辑:程序博客网 时间:2024/06/01 12:55
用enum枚举类实现单例模式:
public enum FastDFSClient { instances; private StorageClient1 storageClient1 = null; private Logger logger = LoggerFactory.getLogger(FastDFSClient.class); FastDFSClient() { TrackerClient tracker = new TrackerClient(); StorageServer storageServer = null; TrackerServer trackerServer = null; while (true) { try { trackerServer = tracker.getConnection(); storageServer = tracker.getStoreStorage(trackerServer); break; } catch (IOException e) { logger.error("create fastDFS fail retry"); try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e1) { logger.warn("thread interrupt"); } } } this.storageClient1 = new StorageClient1(trackerServer, storageServer); } public void init(Map<String, String> map) throws Exception { Properties initPropertie = new Properties(); //只需要设置ip, 其余的使用默认值即可 initPropertie.put(ClientGlobal.PROP_KEY_TRACKER_SERVERS, map.get(BrowserConstants.FASTDFS_SERVERS)); ClientGlobal.initByProperties(initPropertie); TrackerClient tracker = new TrackerClient(); TrackerServer trackerServer = tracker.getConnection(); if (!ProtoCommon.activeTest(trackerServer.getSocket())) { throw new Exception("无法连接到fastDFS"); } } public String uploadFile(byte[] contents) { try { return storageClient1.upload_file1(contents, null, null); } catch (Exception e) { logger.error("fastDFS save error", e); return null; } } public int deleteFile(String file_id) throws Exception { try { return storageClient1.delete_file1(file_id); } catch (Exception e) { logger.error("fastDFS delete error.", e); return 0; } } public int truncateFile(String appender_file_id) { try { return storageClient1.truncate_file1(appender_file_id); } catch (Exception e) { logger.error("fastDFS truncate error", e); return 0; } }}
阅读全文
0 0
- 用enum枚举类实现单例模式
- 使用枚举enum实现单例模式
- 5、单例模式(用枚举enum实现)
- Java枚举enum以及应用:枚举实现单例模式
- Java枚举enum以及应用:枚举实现单例模式
- 使用enum枚举数据类型实现多线程中的单例模式
- 单例模式之使用enum枚举数据类型实现
- 枚举enum的单例模式
- 用enum实现java单例模式
- Enum实现单例模式
- 用枚举实现单例模式
- 最佳单例模式实现方式-单枚举类实现
- java中用enum实现单例模式
- java中用enum实现单例模式
- java中用enum实现单例模式
- 用enum实现单例
- 使用单元素枚举类实现单例模式
- 单元素枚举类实现单例模式
- 金融科技&大数据产品推荐:百融信贷决策审批系统
- 金融科技&大数据产品推荐:蜂巢——数据科学驱动的互联网风控解决方案
- 大数据投融资9月榜:共28起融资事件,总金额超84.7亿元
- JDK的Future源码解析
- 迪拜机场拟用人脸识别取代人工检查,浪潮集团计划在重庆建大数据创客中心 | 大数据24小时
- 用enum枚举类实现单例模式
- 玩转Spring Boot 集成Dubbo
- jquery插件网上下载的问卷调查案例
- HTTP与HTTPS的区别
- VMwareWorkstation克隆centos
- JavaScript 闭包
- 介绍款适合当前金融行业的内存数据库---美国麦科捷eXtremeDB金融版内存数据库系统
- oracle类型和对应的java实体类
- window.setTimeout() 和 window.setInterval() 使用说明