{"id":40775,"date":"2025-05-30T11:15:09","date_gmt":"2025-05-30T03:15:09","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/40775.html"},"modified":"2025-05-30T11:15:09","modified_gmt":"2025-05-30T03:15:09","slug":"%e7%bd%91%e9%a1%b5%e4%ba%94%e5%ad%90%e6%a3%8b%e5%8c%b9%e9%85%8d%e6%a8%a1%e5%9d%97%e7%94%a8%e6%88%b7%e7%ae%a1%e7%90%86%e5%99%a8%e5%8f%af%e8%83%bd%e5%ad%98%e5%9c%a8%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/40775.html","title":{"rendered":"[\u7f51\u9875\u4e94\u5b50\u68cb][\u5339\u914d\u6a21\u5757]\u7528\u6237\u7ba1\u7406\u5668\u53ef\u80fd\u5b58\u5728\u7684\u95ee\u9898\u4ee5\u53ca\u89e3\u51b3\u529e\u6cd5(\u7ebf\u7a0b\u5b89\u5168\u3001\u591a\u5f00\u95ee\u9898)"},"content":{"rendered":"<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\u7ebf\u7a0b\u5b89\u5168<\/li>\n<li>\u591a\u5f00<\/li>\n<li>\n<ul>\n<li>\u539f\u56e0<\/li>\n<li>\u89e3\u51b3\u529e\u6cd5<\/li>\n<li>\u76f8\u5173\u903b\u8f91\u66f4\u6539<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u7ebf\u7a0b\u5b89\u5168<\/h2>\n<p>\u5f53\u524d\u662f\u4f7f\u7528 HashMap \u6765\u5b58\u50a8\u7528\u6237\u7684\u5728\u7ebf\u72b6\u6001\u7684&#xff0c;\u5982\u679c\u662f\u591a\u7ebf\u7a0b\u8bbf\u95ee\u540c\u4e00\u4e2a HashMap&#xff0c;\u5c31\u5bb9\u6613\u51fa\u73b0\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898<\/p>\n<ul>\n<li>\u6bcf\u4e2a\u7528\u6237\u5efa\u7acb\u8fde\u63a5\u6210\u529f\u90fd\u4f1a\u8c03\u7528 afterConnectionEstablished \u65b9\u6cd5<\/li>\n<li>\u6bcf\u4e2a\u7528\u6237\u65ad\u5f00\u8fde\u63a5\u90fd\u4f1a\u8c03\u7528 handleTransportError\/afterConnectionClosed \u8fd9\u4fe9\u65b9\u6cd5 \u5982\u679c\u540c\u65f6\u6709\u591a\u4e2a\u7528\u6237\u548c\u670d\u52a1\u5668\u5efa\u7acb\u8fde\u63a5\/\u65ad\u5f00\u8fde\u63a5&#xff0c;\u6b64\u65f6\u670d\u52a1\u5668\u5c31\u662f\u5e76\u53d1\u7684\u5728\u9488\u5bf9 HashMap \u8fdb\u884c\u4fee\u6539<\/li>\n<\/ul>\n<p>\u8fd9\u91cc\u6211\u4eec\u5c31\u5c06 game.OnlineUserManager \u7c7b\u4e2d\u7684 HashMap \u6539\u4e3a ConcurrentHashMap \u5373\u53ef<\/p>\n<p><span class=\"token keyword\">private<\/span> <span class=\"token class-name\">ConcurrentHashMap<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">Integer<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">WebSocketSession<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> gameHall <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">ConcurrentHashMap<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h2>\u591a\u5f00<\/h2>\n<h3>\u539f\u56e0<\/h3>\n<p>\u5f53\u4e00\u4e2a\u7528\u6237&#xff0c;\u540c\u65f6\u6253\u5f00\u591a\u4e2a\u6d4f\u89c8\u5668&#xff0c;\u540c\u65f6\u8fdb\u884c\u767b\u5f55&#xff0c;\u8fdb\u884c\u6e38\u620f\u5927\u5385\u7684\u65f6\u5019<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530031506-683922bac1fc0.png\" alt=\"image.png|328\" \/><\/p>\n<ul>\n<li>\u5f53\u6d4f\u89c8\u5668 1 \u5efa\u7acb websocket \u8fde\u63a5\u65f6&#xff0c;\u670d\u52a1\u5668\u8fd9\u8fb9\u5c31\u4f1a\u5728 OnlineUserManager \u4e2d\u4fdd\u5b58\u952e\u503c\u5bf9&#xff1a;userId&#061;1&#xff0c;WebSocketSession&#061;session1<\/li>\n<li>\u5f53\u6d4f\u89c8\u5668 2 \u5efa\u7acb websocket \u8fde\u63a5\u65f6&#xff0c;\u670d\u52a1\u5668\u53c8\u4f1a\u5728 OnlineUserManager \u4e2d\u4fdd\u5b58\u952e\u503c\u5bf9&#xff1a;userId&#061;1&#xff0c;WebSocketSession&#061;session2<\/li>\n<li>\u8fd9\u4e24\u6b21\u8fde\u63a5&#xff0c;\u5c1d\u8bd5\u5f80\u54c8\u5e0c\u8868\u4e2d\u5b58\u50a8\u4e24\u4e2a\u952e\u503c\u5bf9&#xff0c;\u4e24\u4e2a\u952e\u503c\u5bf9\u7684 key \u662f\u4e00\u6837\u7684&#xff0c;\u540e\u6765\u7684 value \u4f1a\u8986\u76d6\u4e4b\u524d\u7684 value \u51fa\u73b0\u4e0a\u8ff0\u8fd9\u79cd\u8986\u76d6&#xff0c;\u5c31\u4f1a\u5bfc\u81f4\u7b2c\u4e00\u4e2a\u6d4f\u89c8\u5668\u7684\u8fde\u63a5\u201c\u540d\u5b58\u5b9e\u4ea1\u201d&#xff0c;\u5df2\u7ecf\u62ff\u4e0d\u5230\u5bf9\u5e94\u7684 WebSocketSession \u4e86&#xff0c;\u4e5f\u5c31\u65e0\u6cd5\u7ed9\u8fd9\u4e2a\u6d4f\u89c8\u5668\u63a8\u9001\u6570\u636e\u4e86<\/li>\n<\/ul>\n<h3>\u89e3\u51b3\u529e\u6cd5<\/h3>\n<p>\u591a\u5f00\u4f1a\u4ea7\u751f\u4e0a\u8ff0\u95ee\u9898&#xff0c;\u4f46\u662f\u6211\u4eec\u7684\u7a0b\u5e8f\u662f\u5426\u5e94\u8be5\u5141\u8bb8\u591a\u5f00\u5462&#xff1f;<\/p>\n<ul>\n<li>\u5bf9\u4e8e\u5927\u90e8\u5206\u6e38\u620f\u6765\u8bf4&#xff0c;\u90fd\u662f\u4e0d\u884c\u7684&#xff01;\u90fd\u662f\u7981\u6b62\u591a\u5f00\u7684&#xff0c;\u7981\u6b62\u540c\u4e00\u4e2a\u8d26\u53f7\u5728\u4e0d\u540c\u7684\u4e3b\u673a\u4e0a\u767b\u5f55<\/li>\n<li>\u56e0\u6b64\u6211\u4eec\u8981\u505a\u7684&#xff0c;\u4e0d\u662f\u89e3\u51b3\u4f1a\u8bdd\u8986\u76d6\u7684\u95ee\u9898&#xff0c;\u800c\u662f\u8981\u4ece\u6e90\u5934\u4e0a\u7981\u6b62\u6e38\u620f\u591a\u5f00\n<li>\u8d26\u53f7\u767b\u5f55\u6210\u529f\u4e4b\u540e&#xff0c;\u7981\u6b62\u5728\u5176\u4ed6\u5730\u65b9\u518d\u767b\u5f55&#xff08;\u6211\u4eec\u7528\u7684\u65b9\u6cd5&#xff09;<\/li>\n<li>\u8d26\u53f7\u767b\u5f55\u4e4b\u540e&#xff0c;\u540e\u7eed\u5176\u4ed6\u4f4d\u7f6e\u7684\u767b\u5f55\u4f1a\u628a\u524d\u9762\u7684\u767b\u5f55\u7ed9\u8e22\u6389<\/li>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530031507-683922bb053db.png\" alt=\"image.png\" \/><\/p>\n<p><span class=\"token comment\">\/\/ 2. \u5148\u5224\u5b9a\u5f53\u524d\u7684\u7528\u6237\u662f\u5426\u5df2\u7ecf\u767b\u5f55\u8fc7(\u5df2\u7ecf\u662f\u5728\u7ebf\u72b6\u6001)&#xff0c;\u5982\u679c\u662f\u5df2\u7ecf\u5728\u7ebf&#xff0c;\u5c31\u4e0d\u8be5\u7ee7\u7eed\u8fdb\u884c\u540e\u7eed\u903b\u8f91  <\/span><br \/>\n<span class=\"token class-name\">WebSocketSession<\/span> tmpSession <span class=\"token operator\">&#061;<\/span> onlineUserManager<span class=\"token punctuation\">.<\/span><span class=\"token function\">getFromGameHall<\/span><span class=\"token punctuation\">(<\/span>user<span class=\"token punctuation\">.<\/span><span class=\"token function\">getUserId<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>tmpSession <span class=\"token operator\">!&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5f53\u524d\u7528\u6237\u5df2\u7ecf\u767b\u5f55\u8fc7\u4e86  <\/span><br \/>\n    <span class=\"token comment\">\/\/ \u9488\u5bf9\u8fd9\u4e2a\u60c5\u51b5\u8981\u544a\u77e5\u5ba2\u6237\u7aef&#xff0c;\u4f60\u8fd9\u91cc\u91cd\u590d\u767b\u5f55\u4e86  <\/span><br \/>\n    <span class=\"token class-name\">MatchResponse<\/span> response <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">MatchResponse<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    response<span class=\"token punctuation\">.<\/span><span class=\"token function\">setOk<\/span><span class=\"token punctuation\">(<\/span><span class=\"token boolean\">false<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    response<span class=\"token punctuation\">.<\/span><span class=\"token function\">setReason<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u5f53\u524d\u7981\u6b62\u591a\u5f00!&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    session<span class=\"token punctuation\">.<\/span><span class=\"token function\">sendMessage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">new<\/span> <span class=\"token class-name\">TextMessage<\/span><span class=\"token punctuation\">(<\/span>objectMapper<span class=\"token punctuation\">.<\/span><span class=\"token function\">writeValueAsString<\/span><span class=\"token punctuation\">(<\/span>response<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u4e00\u65e6\u8c03\u7528 close \u65b9\u6cd5&#xff0c;\u5c31\u4f1a\u8c03\u7528\u4e0b\u9762\u7684 afterConnectionClosed \u65b9\u6cd5&#xff0c;\u8fdb\u884c\u670d\u52a1\u4e0b\u7ebf\u64cd\u4f5c  <\/span><br \/>\n    session<span class=\"token punctuation\">.<\/span><span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h3>\u76f8\u5173\u903b\u8f91\u66f4\u6539<\/h3>\n<p>\u5728\u8fde\u63a5\u5efa\u7acb\u903b\u8f91\u8fd9\u91cc&#xff0c;\u505a\u51fa\u4e86\u5224\u5b9a&#xff1a;\u5982\u679c\u73a9\u5bb6\u5df2\u7ecf\u767b\u5f55\u8fc7&#xff0c;\u5c31\u4e0d\u80fd\u518d\u767b\u5f55&#xff0c;\u540c\u65f6\u5173\u95ed websocket \u8fde\u63a5<\/p>\n<ul>\n<li>websocket \u8fde\u63a5\u5173\u95ed\u7684\u8fc7\u7a0b\u4e2d&#xff0c;\u4f1a\u89e6\u53d1 afterConnectionClosed<\/li>\n<li>\u5728\u8fd9\u4e2a\u65b9\u6cd5\u91cc&#xff0c;\u4f1a\u6709\u4e00\u4e2a\u4e0b\u7ebf\u7684\u64cd\u4f5c<\/li>\n<li>\u4f46\u662f\u5728\u8fd9\u4e2a\u4e0b\u7ebf\u7684\u65b9\u6cd5\u91cc&#xff0c;\u662f\u6839\u636e userId \u6765\u8fdb\u884c\u5220\u9664\u7684 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530031507-683922bbcc64e.png\" alt=\"image.png|292\" \/><\/li>\n<li>\u800c\u8fd9\u6837\u5220\u9664\u7684\u8bdd&#xff0c;\u5c31\u4f1a\u628a\u539f\u6765\u7684\u8d26\u53f7\u4e5f\u4e0b\u7ebf&#xff0c;\u56e0\u4e3a\u591a\u5f00\u7684\u65f6\u5019&#xff0c;\u6bcf\u4e2a\u8d26\u53f7\u7684 userId \u90fd\u662f\u4e00\u6837\u7684<\/li>\n<\/ul>\n<p>\u6240\u4ee5\u6211\u4eec\u4e5f\u8981\u5728\u8fd9\u4e2a afterConnectionClosed \u65b9\u6cd5\u91cc\u9762\u4e5f\u8981\u52a0\u5165\u4e00\u4e9b\u5224\u5b9a<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530031508-683922bc670f7.png\" alt=\"image.png|408\" \/><\/p>\n<p><span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">afterConnectionClosed<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">WebSocketSession<\/span> session<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">CloseStatus<\/span> status<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">throws<\/span> <span class=\"token class-name\">Exception<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">try<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u73a9\u5bb6\u4e0b\u7ebf&#xff0c;\u4ece OnlineUserManager \u4e2d\u5220\u9664  <\/span><br \/>\n        <span class=\"token class-name\">User<\/span> user <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token class-name\">User<\/span><span class=\"token punctuation\">)<\/span> session<span class=\"token punctuation\">.<\/span><span class=\"token function\">getAttributes<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;user&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <\/p>\n<p>        <span class=\"token class-name\">WebSocketSession<\/span> tmpSession <span class=\"token operator\">&#061;<\/span> onlineUserManager<span class=\"token punctuation\">.<\/span><span class=\"token function\">getFromGameHall<\/span><span class=\"token punctuation\">(<\/span>user<span class=\"token punctuation\">.<\/span><span class=\"token function\">getUserId<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>tmpSession <span class=\"token operator\">&#061;&#061;<\/span> session<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            onlineUserManager<span class=\"token punctuation\">.<\/span><span class=\"token function\">exitGameHall<\/span><span class=\"token punctuation\">(<\/span>user<span class=\"token punctuation\">.<\/span><span class=\"token function\">getUserId<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">catch<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token class-name\">NullPointerException<\/span> e<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        e<span class=\"token punctuation\">.<\/span><span class=\"token function\">printStackTrace<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">MatchResponse<\/span> response <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">MatchResponse<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        response<span class=\"token punctuation\">.<\/span><span class=\"token function\">setOk<\/span><span class=\"token punctuation\">(<\/span><span class=\"token boolean\">false<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        response<span class=\"token punctuation\">.<\/span><span class=\"token function\">setReason<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u60a8\u672a\u767b\u5f55! \u4e0d\u80fd\u8fdb\u884c\u540e\u7eed\u5339\u914d!&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        session<span class=\"token punctuation\">.<\/span><span class=\"token function\">sendMessage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">new<\/span> <span class=\"token class-name\">TextMessage<\/span><span class=\"token punctuation\">(<\/span>objectMapper<span class=\"token punctuation\">.<\/span><span class=\"token function\">writeValueAsString<\/span><span class=\"token punctuation\">(<\/span>response<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6211\u4eec\u5728\u4e0a\u9762\u7684 handleTransportError \u65b9\u6cd5\u4e2d&#xff0c;\u4e5f\u628a\u76f8\u540c\u7684\u4f4d\u7f6e\u8fdb\u884c\u66f4\u6539<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb123\u6b21\uff0c\u70b9\u8d5e2\u6b21\uff0c\u6536\u85cf2\u6b21\u3002\u672c\u6587\u89e3\u51b3\u4e86WebSocket\u6e38\u620f\u5927\u5385\u4e2d\u7684\u4e24\u4e2a\u5173\u952e\u95ee\u9898\uff1a\u7ebf\u7a0b\u5b89\u5168\u548c\u8d26\u53f7\u591a\u5f00\u3002 \u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\u901a\u8fc7\u5c06\u5b58\u50a8\u7528\u6237\u5728\u7ebf\u72b6\u6001\u7684HashMap\u66ff\u6362\u4e3a\u7ebf\u7a0b\u5b89\u5168\u7684ConcurrentHashMap\u6765\u89e3\u51b3\uff0c\u786e\u4fdd\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u7528\u6237\u8fde\u63a5\u72b6\u6001\u7684\u6b63\u786e\u7ba1\u7406\u3002 \u9488\u5bf9\u8d26\u53f7\u591a\u5f00\u95ee\u9898\uff0c\u91c7\u53d6\u4e86\u7981\u6b62\u7b56\u7565\uff1a\u5f53\u68c0\u6d4b\u5230\u540c\u4e00\u8d26\u53f7\u91cd\u590d\u767b\u5f55\u65f6\uff0c\u76f4\u63a5\u62d2\u7edd\u65b0\u8fde\u63a5\u5e76\u5173\u95ed\u4f1a\u8bdd\u3002\u540c\u65f6\u5728\u8fde\u63a5\u5173\u95ed\u5904\u7406\u4e2d\u4f18\u5316\u4e86\u7528\u6237\u4e0b\u7ebf\u903b\u8f91\uff0c\u786e\u4fdd\u53ea\u79fb\u9664\u5f53\u524d\u4f1a\u8bdd\u5bf9\u5e94\u7684\u7528\u6237\uff0c\u9632\u6b62\u8bef\u5220\u5176\u4ed6\u4f1a\u8bdd\u3002\u901a\u8fc7\u53cc\u91cd\u9a8c\u8bc1\uff08\u83b7\u53d6\u4f1a\u8bdd\u6bd4\u8f83\u548c\u5f02\u5e38\u5904\u7406\uff09\u4fdd\u8bc1\u4e86\u7528\u6237\u72b6\u6001\u7ba1\u7406\u7684\u51c6\u786e\u6027\u548c\u5065\u58ee\u6027\u3002<\/p>\n","protected":false},"author":2,"featured_media":40771,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3728,99,101,98],"topic":[],"class_list":["post-40775","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-3728","tag-java","tag-spring","tag-spring-boot"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[\u7f51\u9875\u4e94\u5b50\u68cb][\u5339\u914d\u6a21\u5757]\u7528\u6237\u7ba1\u7406\u5668\u53ef\u80fd\u5b58\u5728\u7684\u95ee\u9898\u4ee5\u53ca\u89e3\u51b3\u529e\u6cd5(\u7ebf\u7a0b\u5b89\u5168\u3001\u591a\u5f00\u95ee\u9898) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/40775.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[\u7f51\u9875\u4e94\u5b50\u68cb][\u5339\u914d\u6a21\u5757]\u7528\u6237\u7ba1\u7406\u5668\u53ef\u80fd\u5b58\u5728\u7684\u95ee\u9898\u4ee5\u53ca\u89e3\u51b3\u529e\u6cd5(\u7ebf\u7a0b\u5b89\u5168\u3001\u591a\u5f00\u95ee\u9898) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb123\u6b21\uff0c\u70b9\u8d5e2\u6b21\uff0c\u6536\u85cf2\u6b21\u3002\u672c\u6587\u89e3\u51b3\u4e86WebSocket\u6e38\u620f\u5927\u5385\u4e2d\u7684\u4e24\u4e2a\u5173\u952e\u95ee\u9898\uff1a\u7ebf\u7a0b\u5b89\u5168\u548c\u8d26\u53f7\u591a\u5f00\u3002 \u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\u901a\u8fc7\u5c06\u5b58\u50a8\u7528\u6237\u5728\u7ebf\u72b6\u6001\u7684HashMap\u66ff\u6362\u4e3a\u7ebf\u7a0b\u5b89\u5168\u7684ConcurrentHashMap\u6765\u89e3\u51b3\uff0c\u786e\u4fdd\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u7528\u6237\u8fde\u63a5\u72b6\u6001\u7684\u6b63\u786e\u7ba1\u7406\u3002 \u9488\u5bf9\u8d26\u53f7\u591a\u5f00\u95ee\u9898\uff0c\u91c7\u53d6\u4e86\u7981\u6b62\u7b56\u7565\uff1a\u5f53\u68c0\u6d4b\u5230\u540c\u4e00\u8d26\u53f7\u91cd\u590d\u767b\u5f55\u65f6\uff0c\u76f4\u63a5\u62d2\u7edd\u65b0\u8fde\u63a5\u5e76\u5173\u95ed\u4f1a\u8bdd\u3002\u540c\u65f6\u5728\u8fde\u63a5\u5173\u95ed\u5904\u7406\u4e2d\u4f18\u5316\u4e86\u7528\u6237\u4e0b\u7ebf\u903b\u8f91\uff0c\u786e\u4fdd\u53ea\u79fb\u9664\u5f53\u524d\u4f1a\u8bdd\u5bf9\u5e94\u7684\u7528\u6237\uff0c\u9632\u6b62\u8bef\u5220\u5176\u4ed6\u4f1a\u8bdd\u3002\u901a\u8fc7\u53cc\u91cd\u9a8c\u8bc1\uff08\u83b7\u53d6\u4f1a\u8bdd\u6bd4\u8f83\u548c\u5f02\u5e38\u5904\u7406\uff09\u4fdd\u8bc1\u4e86\u7528\u6237\u72b6\u6001\u7ba1\u7406\u7684\u51c6\u786e\u6027\u548c\u5065\u58ee\u6027\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/40775.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-30T03:15:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530031506-683922bac1fc0.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/40775.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/40775.html\",\"name\":\"[\u7f51\u9875\u4e94\u5b50\u68cb][\u5339\u914d\u6a21\u5757]\u7528\u6237\u7ba1\u7406\u5668\u53ef\u80fd\u5b58\u5728\u7684\u95ee\u9898\u4ee5\u53ca\u89e3\u51b3\u529e\u6cd5(\u7ebf\u7a0b\u5b89\u5168\u3001\u591a\u5f00\u95ee\u9898) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-30T03:15:09+00:00\",\"dateModified\":\"2025-05-30T03:15:09+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/40775.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/40775.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/40775.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[\u7f51\u9875\u4e94\u5b50\u68cb][\u5339\u914d\u6a21\u5757]\u7528\u6237\u7ba1\u7406\u5668\u53ef\u80fd\u5b58\u5728\u7684\u95ee\u9898\u4ee5\u53ca\u89e3\u51b3\u529e\u6cd5(\u7ebf\u7a0b\u5b89\u5168\u3001\u591a\u5f00\u95ee\u9898)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[\u7f51\u9875\u4e94\u5b50\u68cb][\u5339\u914d\u6a21\u5757]\u7528\u6237\u7ba1\u7406\u5668\u53ef\u80fd\u5b58\u5728\u7684\u95ee\u9898\u4ee5\u53ca\u89e3\u51b3\u529e\u6cd5(\u7ebf\u7a0b\u5b89\u5168\u3001\u591a\u5f00\u95ee\u9898) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/40775.html","og_locale":"zh_CN","og_type":"article","og_title":"[\u7f51\u9875\u4e94\u5b50\u68cb][\u5339\u914d\u6a21\u5757]\u7528\u6237\u7ba1\u7406\u5668\u53ef\u80fd\u5b58\u5728\u7684\u95ee\u9898\u4ee5\u53ca\u89e3\u51b3\u529e\u6cd5(\u7ebf\u7a0b\u5b89\u5168\u3001\u591a\u5f00\u95ee\u9898) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb123\u6b21\uff0c\u70b9\u8d5e2\u6b21\uff0c\u6536\u85cf2\u6b21\u3002\u672c\u6587\u89e3\u51b3\u4e86WebSocket\u6e38\u620f\u5927\u5385\u4e2d\u7684\u4e24\u4e2a\u5173\u952e\u95ee\u9898\uff1a\u7ebf\u7a0b\u5b89\u5168\u548c\u8d26\u53f7\u591a\u5f00\u3002 \u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\u901a\u8fc7\u5c06\u5b58\u50a8\u7528\u6237\u5728\u7ebf\u72b6\u6001\u7684HashMap\u66ff\u6362\u4e3a\u7ebf\u7a0b\u5b89\u5168\u7684ConcurrentHashMap\u6765\u89e3\u51b3\uff0c\u786e\u4fdd\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u7528\u6237\u8fde\u63a5\u72b6\u6001\u7684\u6b63\u786e\u7ba1\u7406\u3002 \u9488\u5bf9\u8d26\u53f7\u591a\u5f00\u95ee\u9898\uff0c\u91c7\u53d6\u4e86\u7981\u6b62\u7b56\u7565\uff1a\u5f53\u68c0\u6d4b\u5230\u540c\u4e00\u8d26\u53f7\u91cd\u590d\u767b\u5f55\u65f6\uff0c\u76f4\u63a5\u62d2\u7edd\u65b0\u8fde\u63a5\u5e76\u5173\u95ed\u4f1a\u8bdd\u3002\u540c\u65f6\u5728\u8fde\u63a5\u5173\u95ed\u5904\u7406\u4e2d\u4f18\u5316\u4e86\u7528\u6237\u4e0b\u7ebf\u903b\u8f91\uff0c\u786e\u4fdd\u53ea\u79fb\u9664\u5f53\u524d\u4f1a\u8bdd\u5bf9\u5e94\u7684\u7528\u6237\uff0c\u9632\u6b62\u8bef\u5220\u5176\u4ed6\u4f1a\u8bdd\u3002\u901a\u8fc7\u53cc\u91cd\u9a8c\u8bc1\uff08\u83b7\u53d6\u4f1a\u8bdd\u6bd4\u8f83\u548c\u5f02\u5e38\u5904\u7406\uff09\u4fdd\u8bc1\u4e86\u7528\u6237\u72b6\u6001\u7ba1\u7406\u7684\u51c6\u786e\u6027\u548c\u5065\u58ee\u6027\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/40775.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-30T03:15:09+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250530031506-683922bac1fc0.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/40775.html","url":"https:\/\/www.wsisp.com\/helps\/40775.html","name":"[\u7f51\u9875\u4e94\u5b50\u68cb][\u5339\u914d\u6a21\u5757]\u7528\u6237\u7ba1\u7406\u5668\u53ef\u80fd\u5b58\u5728\u7684\u95ee\u9898\u4ee5\u53ca\u89e3\u51b3\u529e\u6cd5(\u7ebf\u7a0b\u5b89\u5168\u3001\u591a\u5f00\u95ee\u9898) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-30T03:15:09+00:00","dateModified":"2025-05-30T03:15:09+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/40775.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/40775.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/40775.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"[\u7f51\u9875\u4e94\u5b50\u68cb][\u5339\u914d\u6a21\u5757]\u7528\u6237\u7ba1\u7406\u5668\u53ef\u80fd\u5b58\u5728\u7684\u95ee\u9898\u4ee5\u53ca\u89e3\u51b3\u529e\u6cd5(\u7ebf\u7a0b\u5b89\u5168\u3001\u591a\u5f00\u95ee\u9898)"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/40775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=40775"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/40775\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/40771"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=40775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=40775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=40775"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=40775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}