package com.sinosoft.config; import com.sinosoft.common.CommonUtil; import java.util.HashMap; import java.util.Map; /** * Created by xushuyi on 2017/12/21. */ public class Test { private static Map hashMap = null; private static Integer num = 0; public static Map initHashMap() { hashMap = new HashMap(); hashMap.put("test", "test"); return hashMap; } public static String test(String api) { hashMap = null;//为了测试重复请求 避免陷入死循环 if (!CommonUtil.isEmpty(hashMap)) { if (hashMap.containsKey(api)) { return api; } } else { if (num < 3) { System.out.println("重复..." + api); initHashMap(); num++; return test(api); } } return null; } public static void main(String[] args) { initHashMap(); System.out.println(test("test")); } }