java优化策略:hashMap内存初始化加载优化
1package com.gsafety.opinion.pc.util; 2 3import java.util.HashMap; 4import java.util.List; 5import java.util.Map; 6 7import javax.annotation.PostConstruct; 8 9import org.springframework.beans.factory.annotation.Autowired; 10import org.springframework.stereotype.Component; 11 12import com.gsafety.opinion.pc.mapper.CountriesMapper; 13import com.gsafety.opinion.pc.mapper.EventTypeMapper; 14import com.gsafety.opinion.pc.mapper.LocationPlaceMapper; 15import com.gsafety.opinion.pc.po.Countries; 16import com.gsafety.opinion.pc.po.EventType; 17import com.gsafety.opinion.pc.po.LocationPlace; 18 19@Component 20public class POCacheUtils { 21 22 public static Map<String,Countries> countriesMap = new HashMap<String,Countries>(); 23 24 public static Map<String,LocationPlace> locationPlacesMap = new HashMap<String,LocationPlace>(); 25 26 public static Map<String,EventType> eventTypeCodeMap = new HashMap<String,EventType>(); 27 28 public static Map<String,EventType> eventTypeNameMap = new HashMap<String,EventType>(); 29 30 @Autowired 31 private CountriesMapper countriesMapper; 32 33 @Autowired 34 private LocationPlaceMapper locationPlaceMapper; 35 36 @Autowired 37 private EventTypeMapper eventTypeMapper; 38 39 @PostConstruct 40 public void init(){ 41 List<Countries> countries=countriesMapper.queryAll(); 42 for(Countries tr:countries){ 43 countriesMap.put(tr.getCode(), tr); 44 45 } 46 List<LocationPlace> locationPlace=locationPlaceMapper.queryAll(); 47 for(LocationPlace tr:locationPlace){ 48 locationPlacesMap.put(tr.getCode(), tr); 49 } 50 List<EventType> eventType=eventTypeMapper.queryAll(); 51 for(EventType tr:eventType){ 52 eventTypeCodeMap.put(tr.getEventCode(), tr); 53 eventTypeNameMap.put(tr.getEventName(), tr); 54 } 55 //List<EventType> EventTypeNames=eventTypeMapper.queryAllName(); 56 } 57 58 59}