{"id":4012,"date":"2019-03-19T16:34:22","date_gmt":"2019-03-19T08:34:22","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=4012"},"modified":"2019-05-24T15:52:15","modified_gmt":"2019-05-24T07:52:15","slug":"%e6%89%8b%e6%8a%8a%e6%89%8b%e6%95%99%e4%bd%a0%e5%86%99%e5%87%ba-6-%e7%a7%8d%e8%b4%9f%e8%bd%bd%e5%9d%87%e8%a1%a1%e7%ae%97%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=4012","title":{"rendered":"\u624b\u628a\u624b\u6559\u4f60\u5199\u51fa 6 \u79cd\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5"},"content":{"rendered":"<p>\u5e38\u89c1\u7684\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5\uff0c\u5927\u6982\u6709 7 \u79cd\u3002\u5b83\u4eec\u5206\u522b\u662f\uff1a\u5b8c\u5168\u968f\u673a\u7b97\u6cd5\u3001\u52a0\u6743\u968f\u673a\u7b97\u6cd5\u3001\u5b8c\u5168\u8f6e\u8be2\u7b97\u6cd5\u3001\u52a0\u6743\u8f6e\u8be2\u7b97\u6cd5\u3001\u5e73\u6ed1\u52a0\u6743\u8f6e\u8be2\u7b97\u6cd5\u3001\u54c8\u5e0c\u7b97\u6cd5\u3001\u6700\u5c0f\u538b\u529b\u7b97\u6cd5\u3002\u672c\u6587\u7ed3\u5408\u6211\u4e2a\u4eba\u7684\u7406\u89e3\uff0c\u7ed9\u5927\u5bb6\u4ece\u5934\u6765\u5199\u51fa 6 \u79cd\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5\u3002<\/p>\n<p>\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5\uff0c\u867d\u7136\u4f60\u5e73\u65f6\u53ef\u80fd\u7528\u4e0d\u5230\uff0c\u4f46\u662f\u9762\u8bd5\u4e2d\u53ef\u80fd\u4f1a\u88ab\u95ee\u5230\u3002\u6bd4\u5982\uff0c\u9762\u8bd5 Dubbo\uff0c\u5c31\u53ef\u80fd\u95ee\u95ee\u4f60\u4e86\u89e3\u4e0d\u4e86\u89e3 Dubbo \u7684\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5\u3002\u8fd8\u6709 Nginx \u7b49\uff0c\u8fd9\u4e9b\u90fd\u548c\u5e76\u53d1\u7f16\u7a0b\u5b58\u5728\u7740\u4e00\u4e9b\u5173\u8054\u3002\u4e86\u89e3\u5b83\u4eec\uff0c\u80fd\u8ba9\u6211\u4eec\u907f\u514d\u5f88\u591a\u5751\u3002<\/p>\n<p><img decoding=\"async\" style=\"width: 350px;height: 390px\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g186px7qppj209q0au783.jpg\" alt=\"\u7b97\u6cd5\"><\/p>\n<p>\u4e0b\u9762\u5148\u770b\u7b2c\u4e00\u79cd\uff0c\u5b8c\u5168\u968f\u673a\u7b97\u6cd5\u3002\u968f\u673a\u5c31\u662f\u6ca1\u6709\u89c4\u5f8b\u7684\uff0c\u968f\u4fbf\u4ece\u8d1f\u8f7d\u4e2d\u83b7\u5f97\u4e00\u53f0\uff0c\u901a\u5e38\u6211\u76f8\u4fe1\u5927\u5bb6\u7b2c\u4e00\u65f6\u95f4\u4f1a\u60f3\u5230\u968f\u673a\u6570\u3002\u5b8c\u5168\u968f\u673a\u7b97\u6cd5\u5c31\u548c\u968f\u673a\u6570\u6709\u4e9b\u5173\u7cfb\u3002\u770b\u4e0b\u9762\u7684\u5b9e\u73b0\u4ee3\u7801\uff1a<\/p>\n<pre class=\"brush:java;\">public static List&lt;String&gt; list = new ArrayList&lt;String&gt;() {\n    {\n        add(\"www.xttblog.com\");\n        add(\"\u516c\u4f17\u53f7\u4e1a\u4f59\u8349\");\n        add(\"\u4e1a\u4f59\u8349\u5fae\u4fe1\u53f7:xmtxtt\");\n    }\n};\nstatic Random random = new Random();\npublic static String go() {\n    int number = random.nextInt(list.size());\n    return list.get(number);\/\/\u968f\u673a\u83b7\u53d6\u670d\u52a1\u5668\n}\npublic static void main(String[] args) {\n    for (int i = 0; i &lt; 15; i++) {\n        System.out.println(go());\n    }\n}<\/pre>\n<p>\u4ee3\u7801\u975e\u5e38\u7684\u7b80\u5355\uff0c\u6211\u5c31\u4e0d\u5728\u8be6\u7ec6\u7684\u89e3\u91ca\u3002\u4e0b\u9762\u518d\u770b\u52a0\u6743\u968f\u673a\u7b97\u6cd5\u3002<\/p>\n<p>\u968f\u673a\u7b97\u6cd5\u6709\u4e00\u4e2a\u7f3a\u70b9\u5c31\u662f\uff0c\u6240\u6709\u7684\u670d\u52a1\u5668\u88ab\u8bbf\u95ee\u5230\u7684\u6982\u7387\u90fd\u662f\u76f8\u540c\u7684\u3002\u5982\u679c\u6211\u67d0\u53f0\u670d\u52a1\u5668\u6027\u80fd\u6bd4\u8f83\u597d\uff0c\u9700\u8981\u968f\u673a\u7684\u6743\u91cd\u9ad8\u4e00\u4e9b\uff0c\u90a3\u8be5\u600e\u4e48\u529e\uff1f\u52a0\u6743\u968f\u673a\u7b97\u6cd5\u5c31\u662f\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush:java;\">public static HashMap&lt;String, Integer&gt; map = new HashMap&lt;String, Integer&gt;() {\n    {\n        put(\"www.xttblog.com\", 2);\n        put(\"\u516c\u4f17\u53f7\u4e1a\u4f59\u8349\", 7);\n        put(\"\u4e1a\u4f59\u8349\u5fae\u4fe1\u53f7:xmtxtt\", 1);\n    }\n};\nstatic Random random = new Random();\npublic static String go() {\n    List&lt;String&gt; ipList = new ArrayList&lt;String&gt;();\n    for (Map.Entry&lt;String, Integer&gt; item : map.entrySet()) {\n        for (int i = 0; i &lt; item.getValue(); i++) {\n            ipList.add(item.getKey());\n        }\n    }\n    int allWeight = map.values().stream().mapToInt(a -&gt; a).sum();\n    int number = random.nextInt(allWeight);\n    return ipList.get(number);\n}\npublic static void main(String[] args) {\n    for (int i = 0; i &lt; 15; i++) {\n        System.out.println(go());\n    }\n}<\/pre>\n<p>\u4ee3\u7801\u4e5f\u975e\u5e38\u7684\u7b80\u5355\u3002\u5c31\u662f\u6839\u636e\u6bcf\u4e2a\u670d\u52a1\u5668\u7684\u6743\u91cd\uff0c\u6dfb\u52a0\u5bf9\u5e94\u6743\u91cd\u6570\u91cf\u7684\u670d\u52a1\u5668\u5230\u96c6\u5408\u4e2d\u3002\u7136\u540e\u4ea7\u751f\u968f\u673a\u7b97\u6cd5\uff0c\u83b7\u53d6\u670d\u52a1\u5668\u5217\u8868\u3002\u6784\u5efa\u4e00\u4e2a\u670d\u52a1\u5668\u7684 List\uff0c\u5982\u679c <a href=\"http:\/\/www.xttblog.com\">www.xttblog.com<\/a>&nbsp;\u670d\u52a1\u5668\u7684\u6743\u91cd\u662f 2\uff0c\u90a3\u4e48\u5f80 List \u91cc\u9762 Add \u4e24\u6b21 <a href=\"http:\/\/www.xttblog.com\">www.xttblog.com<\/a>&nbsp;\u670d\u52a1\u5668\uff0c\u5982\u679c\u201c\u516c\u4f17\u53f7\u4e1a\u4f59\u8349\u201d\u670d\u52a1\u5668\u7684\u6743\u91cd\u662f 7\uff0c\u90a3\u4e48\u6211\u5f80 List \u91cc\u9762 Add 7\u6b21\u201c\u516c\u4f17\u53f7\u4e1a\u4f59\u8349\u201d\u670d\u52a1\u5668\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u7136\u540e\u6211\u518d\u751f\u6210\u4e00\u4e2a\u968f\u673a\u6570\uff0c\u968f\u673a\u6570\u7684\u4e0a\u9650\u5c31\u662f\u6743\u91cd\u7684\u603b\u548c\uff0c\u4e5f\u5c31\u662f List \u7684 Size\u3002\u8fd9\u6837\u6743\u91cd\u8d8a\u5927\u7684\uff0c\u88ab\u9009\u4e2d\u7684\u6982\u7387\u5f53\u7136\u8d8a\u9ad8\u3002\u6743\u91cd\u5927\u7684\u670d\u52a1\u5668\u83b7\u5f97\u7684\u6982\u7387\u5927\u4e00\u4e9b\uff0c\u6743\u91cd\u5c0f\u7684\u670d\u52a1\u5668\u83b7\u5f97\u7684\u6982\u7387\u5c0f\u4e00\u4e9b\u3002<\/p>\n<p>\u8fd9\u4e2a\u7b97\u6cd5\uff0c\u867d\u7136\u89e3\u51b3\u4e86\u6743\u91cd\u95ee\u9898\u3002\u4f46\u662f\uff0c\u5728\u6211\u7684\u6743\u91cd\u8bbe\u7f6e\u8fc7\u5927\u7684\u65f6\u5019\uff0c\u6bd4\u5982\u4e0a\u4e07\uff0c\u4e0a\u5343\u4e07\u3002\u90a3\u4e48\u4f60\u7684 List \u5c31\u4f1a\u88ab\u6491\u7206\u3002\u6240\u4ee5\uff0c\u8fd8\u6709\u53e6\u5916\u4e00\u79cd\u5199\u6cd5\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush:java;\">public static HashMap&lt;String, Integer&gt; map = new HashMap&lt;String, Integer&gt;() {\n    {\n        put(\"www.xttblog.com\", 2);\n        put(\"\u516c\u4f17\u53f7\u4e1a\u4f59\u8349\", 7);\n        put(\"\u4e1a\u4f59\u8349\u5fae\u4fe1\u53f7:xmtxtt\", 1);\n    }\n};\nstatic Random random = new Random();\npublic static String go1() {\n    int allWeight = map.values().stream().mapToInt(a -&gt; a).sum();\n    int number = random.nextInt(allWeight);\n    for (Map.Entry&lt;String, Integer&gt; item : map.entrySet()) {\n        if (item.getValue() &gt;= number) {\n            return item.getKey();\n        }\n        number -= item.getValue();\n    }\n    return \"\";\n}\npublic static void main(String[] args) {\n    for (int i = 0; i &lt; 15; i++) {\n        System.out.println(go1());\n    }\n}<\/pre>\n<p>\u7b97\u6cd5\u539f\u7406\uff1a\u5982\u679c <a href=\"http:\/\/www.xttblog.com\">www.xttblog.com<\/a> \u670d\u52a1\u5668\u7684\u6743\u91cd\u662f 2\uff0c\u201c\u516c\u4f17\u53f7\u4e1a\u4f59\u8349\u201d\u670d\u52a1\u5668\u7684\u6743\u91cd\u662f 7\uff0c\u201c\u4e1a\u4f59\u8349\u5fae\u4fe1\u53f7:xmtxtt\u201d\u670d\u52a1\u5668\u7684\u6743\u91cd\u662f 1\u3002<\/p>\n<ul>\n<li>\u5982\u679c\u6211\u751f\u6210\u7684\u968f\u673a\u6570\u662f 1\uff0c\u90a3\u4e48\u843d\u5230 <a href=\"http:\/\/www.xttblog.com\">www.xttblog.com<\/a> \u670d\u52a1\u5668\uff0c\u56e0\u4e3a 1&lt;=2\uff08<a href=\"http:\/\/www.xttblog.com\">www.xttblog.com<\/a> \u670d\u52a1\u5668\u7684\u6743\u91cd\uff09\n<p>&nbsp;<\/li>\n<li>\u5982\u679c\u6211\u751f\u6210\u7684\u968f\u673a\u6570\u662f 5\uff0c\u90a3\u4e48\u843d\u5230&#8221;\u516c\u4f17\u53f7\u4e1a\u4f59\u8349&#8221;\u670d\u52a1\u5668\uff0c\u56e0\u4e3a 5&gt;2\uff08\u5927\u4e8e <a href=\"http:\/\/www.xttblog.com\">www.xttblog.com<\/a> \u670d\u52a1\u5668\u7684\u6743\u91cd\uff09\uff0c5-2\uff08 <a href=\"http:\/\/www.xttblog.com\">www.xttblog.com<\/a> \u670d\u52a1\u5668\u7684\u6743\u91cd\uff09= 3\uff0c3&lt;7\uff08\u201c\u516c\u4f17\u53f7\u4e1a\u4f59\u8349\u201d\u670d\u52a1\u5668\u7684\u6743\u91cd\uff09\n<p>&nbsp;<\/li>\n<li>\u5982\u679c\u6211\u751f\u6210\u7684\u968f\u673a\u6570\u662f 10\uff0c\u90a3\u4e48\u843d\u5230\u201c\u4e1a\u4f59\u8349\u5fae\u4fe1\u53f7:xmtxtt\u201d\u670d\u52a1\u5668\uff0c\u56e0\u4e3a 10&gt;2\uff08<a href=\"http:\/\/www.xttblog.com\">www.xttblog.com<\/a> \u670d\u52a1\u5668\u7684\u6743\u91cd\uff09\uff0c10-2\uff08<a href=\"http:\/\/www.xttblog.com\">www.xttblog.com<\/a>\u670d\u52a1\u5668\u7684\u6743\u91cd\uff09=8\uff0c8&gt;7\uff08\u201c\u516c\u4f17\u53f7\u4e1a\u4f59\u8349\u201d\u670d\u52a1\u5668\u7684\u6743\u91cd\uff09\uff0c8-7\uff08\u201c\u516c\u4f17\u53f7\u4e1a\u4f59\u8349\u201d\u670d\u52a1\u5668\u7684\u6743\u91cd\uff09=1\uff0c1&lt;=1\uff08\u201c\u4e1a\u4f59\u8349\u5fae\u4fe1\u53f7:xmtxtt\u201d\u670d\u52a1\u5668\u7684\u6743\u91cd\uff09\u3002\n<p>&nbsp;<\/li>\n<\/ul>\n<p>\u968f\u673a\u7b97\u6cd5\u6709\u4e00\u4e2a\u7f3a\u70b9\u5c31\u662f\uff0c\u6709\u65f6\u5019\u6709\u4e9b\u673a\u5668\u53ef\u80fd\u5f88\u957f\u4e00\u6bb5\u65f6\u95f4\u90fd\u968f\u673a\u4e0d\u5230\u3002\u6240\u4ee5\uff0c\u5c31\u53c8\u6709\u4e86\u8f6e\u8be2\u7b97\u6cd5\u3002<\/p>\n<p>\u5b8c\u5168\u8f6e\u8be2\u7b97\u6cd5\uff0c\u975e\u5e38\u7684\u7b80\u5355\uff0c\u4ece\u5934\u5230\u5c3e\uff0c\u5230\u5c3e\u4e86\u540e\uff0c\u518d\u4ece\u5934\u5f00\u59cb\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush:java;\">public static List&lt;String&gt; list = new ArrayList&lt;String&gt;() {\n    {\n        add(\"www.xttblog.com\");\n        add(\"\u516c\u4f17\u53f7\u4e1a\u4f59\u8349\");\n        add(\"\u4e1a\u4f59\u8349\u5fae\u4fe1\u53f7:xmtxtt\");\n    }\n};\nstatic int index;\npublic static String go() {\n    if (index == list.size()) {\n        index = 0;\n    }\n    return list.get(index++);\n}\npublic static void main(String[] args) {\n    for (int i = 0; i &lt; 15; i++) {\n        System.out.println(go());\n    }\n}<\/pre>\n<p>\u4f46\u8fd9\u91cc\u8fd8\u6d89\u53ca\u5230\u4e00\u4e2a\u6743\u91cd\u95ee\u9898\u3002\u56e0\u6b64\u5c31\u53c8\u6709\u4e86\u52a0\u6743\u8f6e\u8be2\u7b97\u6cd5\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush:java;\">public static HashMap&lt;String, Integer&gt; map = new HashMap&lt;String, Integer&gt;() {\n    {\n        put(\"www.xttblog.com\", 2);\n        put(\"\u516c\u4f17\u53f7\u4e1a\u4f59\u8349\", 7);\n        put(\"\u4e1a\u4f59\u8349\u5fae\u4fe1\u53f7:xmtxtt\", 1);\n    }\n};\nstatic Random random = new Random();\nstatic int index;\npublic static String go() {\n    int allWeight = map.values().stream().mapToInt(a -&gt; a).sum();\n    int number = (index++) % allWeight;\n    for (Map.Entry&lt;String, Integer&gt; item : map.entrySet()) {\n        if (item.getValue() &gt; number) {\n            return item.getKey();\n        }\n        number -= item.getValue();\n    }\n    return \"\";\n}\npublic static void main(String[] args) {\n    for (int i = 0; i &lt; 15; i++) {\n        System.out.println(go());\n    }\n}<\/pre>\n<p>\u52a0\u6743\u8f6e\u8be2\uff0c\u770b\u8d77\u6765\u5e76\u6ca1\u4ec0\u4e48\u95ee\u9898\uff0c\u4f46\u662f\u5728\u5b9e\u9645\u4e2d\uff0c\u53ef\u80fd\u67d0\u4e2a\u670d\u52a1\u5668\u6743\u91cd\u5927\uff0c\u957f\u65f6\u95f4\u6267\u884c\u3002\u9047\u5230\u8017\u65f6\u5927\u7684\u8bf7\u6c42\uff0c\u538b\u529b\u975e\u5e38\u7684\u5927\u3002\u5b58\u5728\u7740\u4e0d\u5408\u7406\u6027\u3002\u56e0\u6b64\u5c31\u8bde\u751f\u4e86\u4e00\u79cd\u53eb\u5e73\u6ed1\u52a0\u6743\u8f6e\u8be2\u7b97\u6cd5\u3002<\/p>\n<p>\u4ee3\u7801\u7a0d\u5fae\u591a\u4e00\u70b9\uff0c\u5148\u770b\u4e00\u4e2a\u6743\u91cd\u7c7b\u3002<\/p>\n<pre class=\"brush:java;\">public class SmoothWeightServer {\n    private int weight;\n    private int currentWeight;\n    private String ip;\n    public int getWeight() {\n        return weight;\n    }\n    public void setWeight(int weight) {\n        this.weight = weight;\n    }\n    public int getCurrentWeight() {\n        return currentWeight;\n    }\n    public void setCurrentWeight(int currentWeight) {\n        this.currentWeight = currentWeight;\n    }\n    public String getIp() {\n        return ip;\n    }\n    public void setIp(String ip) {\n        this.ip = ip;\n    }\n    public SmoothWeightServer(int weight, int currentWeight, String ip) {\n        this.weight = weight;\n        this.currentWeight = currentWeight;\n        this.ip = ip;\n    }\n}<\/pre>\n<p>\u6838\u5fc3\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush:java;\">public static HashMap&lt;String, SmoothWeightServer&gt; serverMap = new HashMap&lt;String, SmoothWeightServer&gt;() {\n    {\n        put(\"www.xttblog.com\", new SmoothWeightServer(5,5,\"www.xttblog.com\"));\n        put(\"\u516c\u4f17\u53f7\u4e1a\u4f59\u8349\", new SmoothWeightServer(1,1,\"\u516c\u4f17\u53f7\u4e1a\u4f59\u8349\"));\n        put(\"\u4e1a\u4f59\u8349\u5fae\u4fe1\u53f7:xmtxtt\", new SmoothWeightServer(1,1,\"\u4e1a\u4f59\u8349\u5fae\u4fe1\u53f7:xmtxtt\"));\n    }\n};\npublic static String go() {\n    SmoothWeightServer maxWeightServer = null;\n    int allWeight = serverMap.values().stream().mapToInt(SmoothWeightServer::getWeight).sum();\n    for (Map.Entry&lt;String, SmoothWeightServer&gt; item : serverMap.entrySet()) {\n        SmoothWeightServer currentServer = item.getValue();\n        if (maxWeightServer == null || currentServer.getCurrentWeight() &gt; maxWeightServer.getCurrentWeight()) {\n            maxWeightServer = currentServer;\n        }\n    }\n    assert maxWeightServer != null;\n    maxWeightServer.setCurrentWeight(maxWeightServer.getCurrentWeight() - allWeight);\n    for (Map.Entry&lt;String, SmoothWeightServer&gt; item : serverMap.entrySet()) {\n        SmoothWeightServer currentServer = item.getValue();\n        currentServer.setCurrentWeight(currentServer.getCurrentWeight() + currentServer.getWeight());\n    }\n    return maxWeightServer.getIp();\n}\npublic static void main(String[] args) {\n    for (int i = 0; i &lt; 15; i++) {\n        System.out.println(go());\n    }\n}<\/pre>\n<p>\u7b97\u6cd5\u7684\u539f\u7406\u662f\uff1a\u6bcf\u4e2a\u670d\u52a1\u5668\u90fd\u6709\u4e24\u4e2a\u6743\u91cd\u53d8\u91cf\u3002weight\uff0c\u914d\u7f6e\u6587\u4ef6\u4e2d\u6307\u5b9a\u7684\u8be5\u670d\u52a1\u5668\u7684\u6743\u91cd\uff0c\u8fd9\u4e2a\u503c\u662f\u56fa\u5b9a\u4e0d\u53d8\u7684\uff1bcurrent_weight\uff0c\u670d\u52a1\u5668\u76ee\u524d\u7684\u6743\u91cd\u3002\u4e00\u5f00\u59cb\u4e3a 0\uff0c\u4e4b\u540e\u4f1a\u52a8\u6001\u8c03\u6574\u3002\u6bcf\u6b21\u5f53\u8bf7\u6c42\u5230\u6765\uff0c\u9009\u53d6\u670d\u52a1\u5668\u65f6\uff0c\u4f1a\u904d\u5386\u6570\u7ec4\u4e2d\u6240\u6709\u670d\u52a1\u5668\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u670d\u52a1\u5668\uff0c\u8ba9\u5b83\u7684 current_weight \u589e\u52a0\u5b83\u7684 weight\uff1b\u540c\u65f6\u7d2f\u52a0\u6240\u6709\u670d\u52a1\u5668\u7684 weight\uff0c\u5e76\u4fdd\u5b58\u4e3a total\u3002\u904d\u5386\u5b8c\u6240\u6709\u670d\u52a1\u5668\u4e4b\u540e\uff0c\u5982\u679c\u8be5\u670d\u52a1\u5668\u7684 current_weight \u662f\u6700\u5927\u7684\uff0c\u5c31\u9009\u62e9\u8fd9\u4e2a\u670d\u52a1\u5668\u5904\u7406\u672c\u6b21\u8bf7\u6c42\u3002\u6700\u540e\u628a\u8be5\u670d\u52a1\u5668\u7684 current_weight \u51cf\u53bb total\u3002<\/p>\n<p>\u4e0a\u9762\u7684\u7b97\u6cd5\u867d\u597d\uff0c\u4f46\u662f\u5728\u96c6\u7fa4\u73af\u5883\u4e0b\uff0c\u6211\u60f3\u8ba9\u540c\u4e00\u4e2a\u7528\u6237\u7684\u8bbf\u95ee\uff0c\u5206\u6d41\u5230\u56fa\u5b9a\u7684\u4e00\u53f0\u673a\u5668\u4e0a\uff0c\u600e\u4e48\u529e\uff1f\u6240\u4ee5\u5c31\u53c8\u6709\u4e86\u54c8\u5e0c\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5\u3002<\/p>\n<pre class=\"brush:java;\">public static List&lt;String&gt; list = new ArrayList&lt;String&gt;() {\n    {\n        add(\"www.xttblog.com\");\n        add(\"\u516c\u4f17\u53f7\u4e1a\u4f59\u8349\");\n        add(\"\u4e1a\u4f59\u8349\u5fae\u4fe1\u53f7:xmtxtt\");\n    }\n};\nprivate static String go(String client) {\n    int nodeCount = 20;\n    TreeMap&lt;Integer, String&gt; treeMap = new TreeMap();\n    for (String s : list) {\n        for (int i = 0; i &lt; nodeCount; i++)\n            treeMap.put((s + \"\u2014\u4e1a\u4f59\u8349---\" + i).hashCode(), s);\n    }\n    int clientHash = client.hashCode();\n    SortedMap&lt;Integer, String&gt; subMap = treeMap.tailMap(clientHash);\n    Integer firstHash;\n    if (subMap.size() &gt; 0) {\n        firstHash = subMap.firstKey();\n    } else {\n        firstHash = treeMap.firstKey();\n    }\n    String s = treeMap.get(firstHash);\n    return s;\n}\npublic static void main(String[] args) {\n    for (int i = 0; i &lt; 15; i++) {\n        System.out.println(go(\"\u7528\u6237\u6765\u8bbf\u95ee\" + i));\n    }\n}<\/pre>\n<p>\u4e0a\u9762\u7684 6 \u79cd\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5\u662f\u975e\u5e38\u5e38\u89c1\u7684\uff0c\u5f88\u53ef\u80fd\u5728\u9762\u8bd5\u4e2d\u88ab\u95ee\u5230\u3002\u6211\u8fd9\u91cc\u53ea\u662f\u5b9e\u73b0\uff0c\u5b9e\u9645\u5e94\u7528\u4e2d\u8fd8\u8981\u7ed3\u5408\u5404\u79cd\u8bbe\u8ba1\u6a21\u5f0f\u3002\u53e6\u5916\u53ef\u80fd\u628a\u51e0\u79cd\u7b97\u6cd5\u7ec4\u5408\u8d77\u6765\u7528\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=4012\">\u624b\u628a\u624b\u6559\u4f60\u5199\u51fa 6 \u79cd\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5e38\u89c1\u7684\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5\uff0c\u5927\u6982\u6709 7 \u79cd\u3002\u5b83\u4eec\u5206\u522b\u662f\uff1a\u5b8c\u5168\u968f\u673a\u7b97\u6cd5\u3001\u52a0\u6743\u968f\u673a\u7b97\u6cd5\u3001\u5b8c\u5168\u8f6e\u8be2\u7b97\u6cd5\u3001\u52a0\u6743\u8f6e\u8be2\u7b97\u6cd5\u3001\u5e73\u6ed1\u52a0 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[624,871,1610,626,78],"class_list":["post-4012","post","type-post","status-publish","format-standard","hentry","category-java","tag-dnsgslb","tag-idea","tag-rete","tag-626","tag-78"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4012"}],"version-history":[{"count":3,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4012\/revisions"}],"predecessor-version":[{"id":4271,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/4012\/revisions\/4271"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}