• java常用单例


    public class TerminalServiceHelper {
    // 静态日志对象
    private static final Logger logger = Logger.getLogger(TerminalServiceHelper.class); private TerminalServiceHelper() {      // 私有构造器
          initTerminalService(); }
    // 私有静态实列对象
    private static TerminalServiceHelper instance;
    // 获取实例对象
    public static TerminalServiceHelper getInstance() {
    // 不存在就创建,存在就返回; 如果多线程调用如何保证唯一单例
    if (instance != null) { return instance; } instance = new TerminalServiceHelper(); return instance; } private Map<String, String> serviceMap = new HashMap<String, String>(); public void add(String requestCode, String serviceName) { serviceMap.put(requestCode, serviceName); }

         

        private void initTerminalService() {
          // 初始化bean名称到集合对象中

          add("1001", "cardSignedService");

        }

    public IBaseWebserviceService getService(String requestCode, ServletContext ctx) throws ParamException {
            WebApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(ctx);
            IBaseWebserviceService geposAppService = null;
            try {
                geposAppService = (IBaseWebserviceService) springContext.getBean(serviceMap.get(requestCode));
            } catch (Exception e) {
                logger.error(e.getMessage(),e);
                throw new ParamException("请求类型不正常,请确认后重试:"+e.getMessage());
            }
            return geposAppService;
        }
    
    }
  • 相关阅读:
    多点触摸的一些代码
    精灵跳跃练习
    svn安装所遇到的几个问题[转载]
    简易包边字画法
    http和socket简介
    ant使用笔记
    j2se图片拖拽练习
    A星寻路示例
    迅为瑞芯微iTOP3399开发板资料更新
    迅为i.MX6Q开发板NXP恩智浦ARM安卓linux开发板
  • 原文地址:https://www.cnblogs.com/zhangmo/p/15566112.html
Copyright © 2020-2023  润新知