• java优化策略:hashMap内存初始化加载优化


     java优化策略:hashMap内存初始化加载优化

    package com.gsafety.opinion.pc.util;
    
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import javax.annotation.PostConstruct;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Component;
    
    import com.gsafety.opinion.pc.mapper.CountriesMapper;
    import com.gsafety.opinion.pc.mapper.EventTypeMapper;
    import com.gsafety.opinion.pc.mapper.LocationPlaceMapper;
    import com.gsafety.opinion.pc.po.Countries;
    import com.gsafety.opinion.pc.po.EventType;
    import com.gsafety.opinion.pc.po.LocationPlace;
    
    @Component
    public class POCacheUtils {
        
        public static Map<String,Countries> countriesMap = new HashMap<String,Countries>();
        
        public static Map<String,LocationPlace> locationPlacesMap = new HashMap<String,LocationPlace>();
        
        public static Map<String,EventType> eventTypeCodeMap = new HashMap<String,EventType>();
        
        public static Map<String,EventType> eventTypeNameMap = new HashMap<String,EventType>();
        
        @Autowired
        private CountriesMapper countriesMapper;
        
        @Autowired
        private LocationPlaceMapper locationPlaceMapper;
        
        @Autowired
        private EventTypeMapper eventTypeMapper;
        
        @PostConstruct
        public void init(){
            List<Countries> countries=countriesMapper.queryAll();        
            for(Countries tr:countries){
                countriesMap.put(tr.getCode(), tr);
                
            }
            List<LocationPlace> locationPlace=locationPlaceMapper.queryAll();
            for(LocationPlace tr:locationPlace){
                locationPlacesMap.put(tr.getCode(), tr);            
            }
            List<EventType> eventType=eventTypeMapper.queryAll();
            for(EventType tr:eventType){
                eventTypeCodeMap.put(tr.getEventCode(), tr);
                eventTypeNameMap.put(tr.getEventName(), tr);
            }
            //List<EventType> EventTypeNames=eventTypeMapper.queryAllName();
        }
        
    
    }
  • 相关阅读:
    PHP mysqli 扩展库(面向对象/数据库操作封装/事务控制/预编译)
    php 下载文件的函数
    PBOC电子钱包与电子现金及QPBOC
    基于PBOC电子钱包的消费过程详解
    PBOC规范下的java卡介绍
    基于PBOC电子钱包的圈存过程详解
    电子钱包和电子现金的区别
    DES,3DES,AES这三种对称密钥的区别与联系
    密钥体系
    关于卡片的主控密钥和应用主控密钥
  • 原文地址:https://www.cnblogs.com/ComputerVip/p/12503872.html
Copyright © 2020-2023  润新知