Map<String, Object> resultMap = new HashMap<>(); private static byte[] lock = new byte[0]; @Override public String saveMap(String id) { String key = ""; if (null != id && !"".equals(id)) { synchronized (lock) { / 当前时间戳 long currentTime = System.currentTimeMillis(); key = currentTime + "" + UUID.randomUUID(); resultMap.put(key, id); } } return key; } @Override public void removeMap(String mapKey) { if (null != mapKey && !"".equals(mapKey)) { synchronized (lock) { resultMap.remove(mapKey); } } } @Override public String getMap(String mapKey) { String result = ""; if (null != mapKey && !"".equals(mapKey)) { synchronized (lock) { result = (String) resultMap.get(mapKey); } } return result; }
map小缓存.Map HashMap
最新推荐文章于 2022-01-27 16:08:19 发布