{"id":2758,"date":"2022-02-25T12:35:19","date_gmt":"2022-02-25T04:35:19","guid":{"rendered":"https:\/\/ufqi.com\/blog\/?p=2758"},"modified":"2022-03-14T13:12:22","modified_gmt":"2022-03-14T05:12:22","slug":"gwa2-java-multiple-threads-globaldata","status":"publish","type":"post","link":"https:\/\/ufqi.com\/blog\/gwa2-java-multiple-threads-globaldata\/","title":{"rendered":"GWA2 Java \u589e\u52a0\u591a\u7ebf\u7a0b\u6570\u636e\u5171\u4eab\u901a\u9053 globalData"},"content":{"rendered":"\n<p>\u4ee4\u4e3e\u56fd\u6c11\u4f17\u9707\u60ca\u7684\u6c5f\u82cf\u5f90\u5dde\u4e30\u53bf\u94c1\u94fe\u5973\uff08\u751f\u80b2\u516b\u5b69\u5973\u5b50\uff09\u4e00\u4e8b\u9010\u6e10\u88ab\u6d88\u97f3\uff08 https:\/\/ufqi.com\/news\/ulongpage.3651.html?tit=\u4ecd\u7559\u4e0b\u5f90\u5dde\u4e30\u53bf\u751f\u80b2\u516b\u5b69\u5973\u5b50\u72ec\u81ea\u9762\u5bf9\u547d\u8fd0\uff5c\u8206\u8bba\u624b\u672d \uff09\uff0c\u4eca\u6682\u4e14\u4e0d\u8bba\u3002<\/p>\n\n\n\n<p>GWA2 Java \u6700\u8fd1\u88ab\u90e8\u7f72\u5230\u4e00\u4e2a\u91d1\u878d\u7c7b\u9879\u76ee\uff08 \u6709\u798f\u91d1\u878d\uff1ahttps:\/\/ufqi.com\/finance \uff09\u4e0a\u8fd0\u884c\u4e4b\u540e\uff0c\u6301\u7eed\u9047\u5230\u5e76\u53d1\u3001\u6570\u636e\u540c\u6b65\u3001\u591a\u8fdb\u7a0b\u591a\u7ebf\u7a0b\u6570\u636e\u8bbf\u95ee\u63a7\u5236\u7684\u6311\u6218\u3002\u5728\u6b64\u524d\u4e00\u7bc7\u7684\u535a\u5ba2\u4e2d\uff0c\u6211\u4eec\u8ba8\u8bba\u4e86\u5728\u6570\u636e\u540c\u6b65\u65f6\u7684\u6570\u636e\u52a0\u9501\u7684\u8fc7\u7a0b\u7ec6\u8282\uff1aSynchronized\u540c\u6b65Quque\u961f\u5217Concurrency\u5e76\u53d1\u4e0e\u7ebf\u7a0b\u9501Lock \uff08 https:\/\/ufqi.com\/blog\/gwa2-php-synchronized\/ \uff09\u3002 \u4eca\u5929\u7ee7\u7eed\u8fd9\u4e2a\u8bdd\u9898\uff0c\u8ba8\u8bba GWA2 Java \u5bc4\u5bbf\u4e8e Apache Tomcat\u4e2d\u591a\u8fdb\u7a0b\u591a\u7ebf\u7a0b\u7f16\u7a0b\u53ca\u8fd0\u884c\u65f6\u73af\u5883\u4e0b\uff0c\u5982\u4f55\u5b9e\u73b0\u5bf9\u591a\u7ebf\u7a0b\u95f4\u6570\u636e\u7684\u9694\u79bb\u4e0e\u5171\u4eab\u3002<\/p>\n\n\n\n<p>\u524d\u6587\u8bb0\u8ff0\uff0c\u5728Apache Tomcat \u7b49\u5bb9\u5668\u4e2d\uff0c\u5b9e\u73b0\u5bf9\u6570\u636e\u7684\u5b89\u5168\u7ba1\u63a7\u7684\u6700\u597d\u7684\u65b9\u5f0f\u662f\u4f7f\u7528 Synchronized \u540c\u6b65\u673a\u5236\uff0c\u8ba9\u7a0b\u5e8f\u5355\u7ebf\u7a0b\u8fd0\u884c\uff0c\u4f46\u8fd9\u5f88\u96be\u5728Application\u5c42\u9762\u6269\u5c55\u5904\u7406\u80fd\u529b\u3002\u4e8e\u662f\u6211\u4eec\u4fee\u6539\u4e86\u89c4\u5219\uff0c\u9ed8\u8ba4\u4e0d\u518d\u542f\u7528 synchronized\u540c\u6b65\u673a\u5236\u5728\u5168\u5c40\u3002\u8fd9\u6837 GWA2 Java \u91cd\u65b0\u56de\u5230\u591a\u8fdb\u7a0b\u591a\u7ebf\u7a0b\u8fd0\u884c\u73af\u5883\uff0c\u5e76\u53d1\u6269\u5c55\u80fd\u529b\u6fc0\u589e\u3002\u968f\u4e4b\u800c\u6765\u7684\u5c31\u662f\u5728\u591a\u7ebf\u7a0b\u8fd0\u884c\u65f6\u73af\u5883\u4e0b\uff0c\u6570\u636e\u7684\u9694\u79bb\u4e0e\u5171\u4eab\u3002<br \/>\u6709\u4e9b\u6570\u636e\u662f\u9700\u8981\u9694\u79bb\u7684\uff0c\u6bd4\u5982\u5728\u591a\u7ebf\u7a0b\u5e76\u53d1\u8fd0\u884c\u65f6\u73af\u5883\u4e0b\uff0c\u5f53\u8bf7\u6c421\u88ab\u7ebf\u7a0bA\u63a5\u7ba1\u7684\u540c\u65f6\uff0c\u8bf7\u6c422\u88ab\u7ebf\u7a0bB\u63a5\u7ba1\uff0c\u5982\u679c\u4e0d\u505a\u6570\u636e\u9694\u79bb\u7684\u8bdd\uff0c\u5728\u6574\u4e2a\u8fdb\u7a0b\u4e2d\u7684\u6570\u636e\u90fd\u4f1a\u88ab\u91cd\u7f6e\u4e3a\u8f83\u540e\u8005\u8fdb\u6765\u7684\u8bf7\u6c42\u3002<br \/>\u6211\u4eec\u9700\u8981\u67d0\u79cd\u673a\u5236\u5c06\u8bf7\u6c42\u7684\u5404\u79cd\u6570\u636e\u9650\u5236\u5728\u7ebf\u7a0b\u5185\u3002<\/p>\n\n\n\n<p>\u540c\u65f6\uff0c\u6709\u4e9b\u6570\u636e\u53c8\u9700\u8981\u88ab\u5171\u4eab\uff0c\u4e00\u4e2a\u63a5\u53e3\u6216\u8fdb\u7a0b\u542f\u52a8\u540e\uff0c\u603b\u6709\u4e00\u4e9b\u5168\u5c40\u6027\u7684\u8bbe\u7f6e\u6216\u53d8\u91cf\uff0c\u9700\u8981\u80fd\u591f\u5728\u6240\u6709\u7ebf\u7a0b\u4e2d\u88ab\u8bbf\u95ee\u5230\u3002\u8fd9\u53c8\u8981\u6c42\u6211\u4eec\u5fc5\u9700\u63d0\u4f9b\u67d0\u79cd\u673a\u5236\u80fd\u591f\u6ee1\u8db3\uff0c\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\uff0c\u5bf9\u4e00\u4e9b\u5168\u5c40\u6570\u636e\u7684\u8bfb\u5199\u8bbf\u95ee\uff0c\u5e76\u4fdd\u969c\u8fd9\u4e9b\u6570\u636e\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff08Thread-Safe\uff09\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2022\/02\/\u7ebf\u7a0b\u9501\u95f4\u5171\u4eab\u53d8\u91cf-2.png\"><img loading=\"lazy\" width=\"712\" height=\"391\" src=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2022\/02\/\u7ebf\u7a0b\u9501\u95f4\u5171\u4eab\u53d8\u91cf-2.png\" alt=\"\" class=\"wp-image-2759\" srcset=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2022\/02\/\u7ebf\u7a0b\u9501\u95f4\u5171\u4eab\u53d8\u91cf-2.png 712w, https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2022\/02\/\u7ebf\u7a0b\u9501\u95f4\u5171\u4eab\u53d8\u91cf-2-300x165.png 300w\" sizes=\"(max-width: 712px) 100vw, 712px\" \/><\/a><figcaption>fig1.\u5355\u7ebf\u7a0b\u4e0e\u591a\u7ebf\u7a0b\u8fd0\u884c\u65f6\u72b6\u6001\u793a\u610f\u56fe<\/figcaption><\/figure>\n\n\n\n<p>\u5728\u4e00\u756a\u5206\u6790\u548c\u63a2\u7d22\u4e4b\u540e\uff0c\u6211\u4eec\u5bf9GWA2 Java\u505a\u4e86\u5982\u4e0b\u6539\u8fdb\u548c\u5347\u7ea7\uff0c\u4ee5<strong>\u5b9e\u73b0GWA2 Java\u4ece &#8220;\u7ebf\u7a0b\u4e0d\u5b89\u5168&#8212;\u5355\u7ebf\u7a0b\u5b89\u5168&#8212;\u591a\u7ebf\u7a0b\u5b89\u5168&#8221; \u7684\u6f14\u8fdb<\/strong>\u3002<\/p>\n\n\n\n<p><strong>1\/3. \u6539\u8fdb\u5168\u5c40\u6570\u636e\u5bb9\u5668data\u7684\u7c7b\u578b\uff1a\u7528ConcurrentHashMap\u53d6\u4ee3HashMap<\/strong><\/p>\n\n\n\n<p>\u8131\u80ce\u4e8eGWA2 PHP\uff0c\u6211\u4eec\u59cb\u7ec8\u8ba4\u4e3a\u9700\u8981\u4e00\u4e2a\u5168\u5c40\u6027\u7684\u6570\u636e\u5bb9\u5668\uff0c\u53ef\u4ee5\u5c06\u4efb\u52a1\/\u4e1a\u52a1\u5904\u7406\u8fc7\u7a0b\u4e2d\u6240\u4ea7\u751f\u7684\u6570\u636e\u4e34\u65f6\u5b58\u653e\u8d77\u6765\uff0c\u8fd9\u4e2a\u6570\u636e\u5bb9\u5668\u65e0\u7591\u7c7b\u578b\u662f\u4e00\u4e2a\u5b57\u5178\u8868\u4e4b\u7c7b\u3002\u5728GWA2 Java\u4e2d\uff0c\u8d77\u521d\u4f7f\u7528\u4e86 HashMap\uff08\u975e\u7ebf\u7a0b\u5b89\u5168\u7684\uff09\uff0c\u540e\u6765\u9047\u5230\u6570\u636e\u540c\u6b65\u95ee\u9898\u540e\uff0c\u4f7f\u7528Synchronized\u540c\u6b65\u5173\u952e\u8bcd\u5f97\u4ee5\u4e34\u65f6\u89e3\u51b3\u3002<br \/>\u518d\u6b21\u7684\u63a2\u7d22\u7814\u7a76\uff0c\u6211\u4eec\u8ba4\u4e3a\u662f\u65f6\u5019\u4f7f\u7528 ConcurrentHashMap\u66ff\u4ee3HashMap \u4e86\uff0cConcurrentHashMap \u5bf9\u591a\u7ebf\u7a0b\u6709\u66f4\u597d\u7684\u652f\u6301\uff0c\u800c\u4e14\u662fJava\u539f\u751f\u7684\u6570\u636e\u7c7b\u578b\u3002<br \/>\u4ee3\u4ef7\u4e5f\u662f\u6709\u7684\uff0c\u6bd5\u7adfConcurrentHashMap\u5728\u6570\u636e\u8bfb\u5199\u65f6\uff0c\u8981\u5904\u7406\u7ebf\u7a0b\u9501\u7684\u95ee\u9898\uff0c\u56e0\u4e3a\u5728\u6570\u636e\u5904\u7406\u4e0a\u5f00\u9500\u66f4\u5927\uff0c\u901f\u5ea6\u7a0d\u6162\u3002<br \/>\u53e6\u5916\u4ee4\u4eba\u4e0d\u597d\u63a5\u53d7\u7684\u662f\uff0cConcurrentHashMap\u4e0d\u63a5\u53d7null\u7a7a\u503c\uff0ckey\u6216\u8005value\uff0c\u90fd\u4e0d\u884c\uff0c\u8fd9\u65e0\u7591\u5bf9\u4e8e\u75db\u6068Java null\u7684\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u5c06\u4f1a\u66f4\u52a0\u591a\u5730\u8981\u6ce8\u610f\uff0c\u5b58\u50a8data\u6570\u636e\u65f6\uff0c\u9700\u8981\u8003\u8651\u5230\u662f\u5426null\u7684\u524d\u7f6e\u5224\u65ad\u3002<\/p>\n\n\n\n<p><strong>2\/3. \u6539\u8fdb\u591a\u6570\u5168\u5c40\u53d8\u91cf\u7684\u4f5c\u7528\u57df\uff0c\u7531\u5bf9\u8c61\u7c7b\u7684\u4f5c\u7528\u57df\u7f29\u5c0f\u5230\u65b9\u6cd5\u4f53\u7684\u4f5c\u7528\u57df<\/strong><\/p>\n\n\n\n<p>\u5728\u524d\u4e00\u8282\u6539\u52a8\u4f7f\u7528 ConcurrentHashMap \u53d6\u4ee3HashMap\u540e\uff0cdata\u5bb9\u5668\u7684\u786e\u662f\u6570\u636e\u5b89\u5168\u4e86\uff0c\u53ef\u8bf7\u6c42\u6570\u636e\u5728\u5e76\u53d1\u60c5\u51b5\u4e0b\u88ab\u91cd\u5199\u7684\u95ee\u9898\u4ecd\u5728\u3002\u8fd9\u6e90\u4e8e\u6211\u4eec\u5728  JSP\u6587\u4ef6\u4e2d\u58f0\u660e\u53d8\u91cf\u65f6\uff0c\u4f7f\u7528!\u611f\u53f9\u53f7\u8fd9\u6837\u7684\u6b66\u5668\u3002<\/p>\n\n\n\n<p>&lt;%!HashMap data;%&gt;<br \/>\u5c06\u4f1a\u751f\u6210\u4e00\u4e2a\u4f5c\u7528\u57df\u4e3a\u5bf9\u8c61\u7c7b\u7684\u53d8\u91cfdata<br \/>&lt;%HashMap data%&gt;<br \/>\u5c06\u4f1a\u751f\u6210\u4e00\u4e2a\u4f5c\u7528\u57df\u4e3a\u65b9\u6cd5\u4f53\u7684\u53d8\u91cfdata<\/p>\n\n\n\n<p>\u8fd9\u5176\u4e2d\u7684\u7ec6\u8282\u53ef\u80fd\u8981\u53c2\u8003Java Servlet\u76f8\u5173\u6280\u672f\u89c4\u7f5a\u624b\u518c\u3002<\/p>\n\n\n\n<p>\u6839\u636eApache Tomcat\u9ed8\u8ba4\u80fd\u591f\u5c06\u6bcf\u4e00\u4e2a\u8bf7\u6c42\u5206\u53d1\u5230\u4e00\u4e2a\u7ebf\u7a0b\u5904\u7406\u7684\u673a\u5236\uff0c\u7ed3\u5408fig1.\u4e2d\u5bf9\u591a\u7ebf\u7a0b\u7684\u63cf\u8ff0\uff0c\u6211\u4eec\u53d1\u73b0\u5c06\u6570\u636e\u5bb9\u5668data\u7684\u4f5c\u7528\u57df\u7531\u5bf9\u8c61\u7c7b\u7f29\u5c0f\u5230\u65b9\u6cd5\u4f53\u5185\uff0c\u662f\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u7b54\u6848\u3002<br \/>\u8fd9\u5c31\u89e3\u51b3\u4e86\u8bf7\u6c42\u6570\u636e\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u7684\u6570\u636e\u9694\u79bb\u95ee\u9898\uff0c\u5f53GWA2 Java\u6240\u9700\u8981\u7684\u6570\u636e\u5bb9\u5668\u53ca\u5176\u4ed6\u591a\u6570\u53d8\u91cf\u90fd\u5df2\u7ecf\u5185\u7f6e\u4e8e\u7ebf\u7a0b\u5185\uff08register\u548cstack\u533a\u57df\uff09\uff0c\u5176\u6570\u636e\u81ea\u7136\u662f\u88ab\u5b8c\u5168\u9694\u79bb\u7684\u4e86\u3002<\/p>\n\n\n\n<p>\u6539\u52a8\u4e5f\u662f\u6709\u4ee3\u4ef7\u7684\uff0c\u5f53\u6211\u4eec\u505a\u8fd9\u6837\u7684\u4fee\u6539\u540e\uff0cdata\u8fd9\u6837\u7684\u201c\u5168\u5c40\u201d\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u51cf\u5c11\u4e86\uff0c\u662f\u4e3a\u4e86\u7ebf\u7a0b\u95f4\u6570\u636e\u9694\u79bb\uff0c\u540c\u65f6\u4e5f\u963b\u788d\u4e86\u6211\u4eec\u5728\u4efb\u4f55\u4ee3\u7801\u5757\u4e2d\u8bbf\u95ee\u548c\u4f7f\u7528\u8fd9\u4e9b\u6570\u636e\u3002<br \/>\u6bd4\u5982\u5728\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u65b9\u6cd5\u4f53\u5185\uff0c\u5728\u6b64\u6539\u52a8\u4e4b\u524d\uff0c\u53ef\u4ee5\u76f4\u63a5\u8bfb\u53d6\u548c\u5199\u5165\u64cd\u4f5cdata\uff0c \u800c\u8fd9\u6b21\u4fee\u6539\u4e4b\u540e\uff0c\u5c06\u4e0d\u80fd\u5bf9data\u6570\u636e\u8fdb\u884c\u4efb\u4f55\u8bfb\u53d6\u6216\u5199\u5165\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p><strong>3\/3. \u589e\u52a0\u7ebf\u7a0b\u95f4\u6570\u636e\u5171\u4eab\u901a\u9053 globalData<\/strong><\/p>\n\n\n\n<p>\u6539\u8fdb\u5230\u524d\u4e24\u6b65\u5df2\u7ecf\u5b9e\u73b0\u4e86\u591a\u7ebf\u7a0b\u5b89\u5168\u7684GWA2 Java\u8fd0\u884c\u65f6\u73af\u5883\u4fdd\u8bc1\u3002\u4f46\u6211\u4eec\u8fd8\u4e0d\u6ee1\u8db3\u4e8e\u6b64\uff0c\u6211\u4eec\u4ecd\u5e0c\u671bGWA\u4fdd\u6301\u6574\u4e2a\u5957\u7cfb\u7684\u98ce\u683c\uff0c\u5728GWA2 PHP\u4e2d\uff0c\u5168\u5c40\u53d8\u91cf data \u59cb\u7ec8\u662f\u5168\u5c40\u7684\uff0c\u4efb\u4f55\u4ee3\u7801\u7a7a\u95f4\u90fd\u53ef\u4ee5\u8bbf\u95ee\u5230\u3002<br \/>\u57282\/3.\u6539\u52a8\u4e4b\u524d\uff0c GWA2 Java\u4e5f\u80fd\u591f\u63d0\u4f9b\u8fd9\u79cd\u5168\u5c40\u8bbf\u95ee\u7684\u4fbf\u5229\u6027\uff0c\u90a3\u662f\u4ee5\u9760Synchronized\u540c\u6b65\u673a\u5236\u63d0\u4f9b\u4e86\u5355\u7ebf\u7a0b\u73af\u5883\u3002\u6709\u6ca1\u6709\u53ef\u80fd\u5728 2\/3.\u591a\u7ebf\u7a0b\u8fd0\u884c\u65f6\u73af\u5883\u4e0b\uff0c\u4e5f\u63d0\u4f9b\u4e00\u4e2a\u5177\u6709\u5168\u5c40\u8bbf\u95ee\u4fbf\u5229\u6027\u7684\u6570\u636e\u5bb9\u5668data\uff1f<\/p>\n\n\n\n<p>\u7b54\u6848\u662f\u80af\u5b9a\u7684\uff0c\u6211\u4eec\u4e3aGWA2 Java\u589e\u52a0\u4e86\u7ebf\u7a0b\u95f4\u6570\u636e\u5171\u4eab\u901a\u9053 globalData.<\/p>\n\n\n\n<p>\u901a\u8fc7\u4e4b\u524d\u7b2c\u4e8c\u6b65\u7684\u6539\u8fdb\u6211\u4eec\u77e5\u9053\uff0c\u5f53\u4f7f\u7528!\u611f\u53f9\u53f7\u6807\u8bb0\u7684\u53d8\u91cf\u58f0\u660e\u65f6\uff0c\u5373\u53ef\u58f0\u660e\u4e00\u4e2a\u4f5c\u7528\u57df\u4e3a\u5bf9\u8c61\u7c7b\u7684\u53d8\u91cf\uff08fig1.\u4e2d\u7684code\u548cdata\u533a\u57df\uff09\uff0c\u8fd9\u4e2a\u53d8\u91cf\u53ef\u4ee5\u5728\u6240\u6709\u7ebf\u7a0b\u53ef\u89c1\uff0c\u5728\u5f53\u524d\u5bf9\u8c61\u7c7b\u7684\u6240\u6709\u65b9\u6cd5\u4f53\u53ef\u89c1\u3002<br \/>\u5982\u679c\u628a\u5b83\u58f0\u660e\u4e3aConcurrentHashMap\uff0c\u5176\u81ea\u8eab\u6570\u636e\u5c06\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u540c\u65f6\u5982\u679c\u518d\u8fdb\u4e00\u6b65\u63d0\u4f9b\u67d0\u79cd\u673a\u5236\uff0c\u4fdd\u8bc1\u6bcf\u4e2a\u7ebf\u7a0b\u90fd\u80fd\u591f\u901a\u8fc7\u5b83\u8bfb\u53d6\u5230\u7ebf\u7a0bId\u76f8\u5173\u7684\u6570\u636e\uff0c\u5219\u53c8\u5b9e\u73b0\u4e86\u7ebf\u7a0b\u95f4\u7684\u6570\u636e\u5dee\u5f02\u3002<br \/>\u6cbf\u7740\u8fd9\u4e2a\u601d\u8def\uff0c\u6211\u4eec\u5b9a\u4e49GWA2 Java\u591a\u7ebf\u7a0b\u95f4\u6570\u636e\u5171\u4eab\u901a\u9053 globalData \u3002<\/p>\n\n\n\n<p>&lt;%!ConcurrentHashMap globalDataHolder;%&gt;<br \/>&lt;%globalDataHolder = new ConcurrentHashMap();%&gt;<br \/>&lt;%!<br \/>\/\/- write\/read global data into\/from a thread-safe holder, 09:18 2022-02-24<br \/>\/\/- write<br \/>public static void globalData(String key, Object value){ .<br \/>    String threadDataKey = &#8220;GWA2-&#8221; + ProcessHandle.current().pid() + &#8220;-&#8221; + Thread.currentThread().getId();<br \/>.. }<br \/>\/\/- read<br \/>public static Object globalData(String key){ &#8230; }<br \/>%&gt;<\/p>\n\n\n\n<p>\u5982\u6b64\u4ee5\u6765\uff0c\u6211\u4eec\u62e5\u6709\u4e86\u5168\u5c40\u7684\u6570\u636e\u5bb9\u5668globalDataHolder, \u53ea\u662f\u5b83\u7684\u8bfb\u5199\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u4f46\u6570\u636e\u5e76\u4e0d\u662f\u7ebf\u7a0b\u5b89\u5168\u7684(\u6ca1\u6709\u7ebf\u7a0b\u6807\u8bb0)\uff0c\u8bfb\u5199\u5e26\u6709\u7ebf\u7a0bId\u6807\u8bb0\u7684\u6570\u636e\u65f6\uff0c\u9700\u8981\u901a\u8fc7\u5168\u5c40\u9759\u6001\u65b9\u6cd5 globalData .<br \/>\u9884\u671f\u4f7f\u7528\u573a\u666f\uff0c \u5728GWA2 Java\u7684\u4efb\u4f55\u4ee3\u7801\u533a\u57df\uff0c\u53ef\u4ee5\u8bbf\u95ee\u5230 globalData, \u901a\u8fc7\u8fd9\u4e2a\u901a\u9053\u53ef\u4ee5\u8f7b\u677e\u8bfb\u5199\u7ebf\u7a0b\u5b89\u5168\u7684\u6570\u636e\u3002<br \/>\u4efb\u610f\u4ee3\u7801\u533a\uff0c\u5199\u6570\u636e: globalData(&#8220;a-key-name&#8221;, Single_Value_Or_List_Object);<br \/>\u8bfb\u53d6\u6570\u636e:  String aString = (String)globalData(&#8220;a-string-key&#8221;);<\/p>\n\n\n\n<p>\u5728GWA2 Java\u7684\u8bf7\u6c42\u5904\u7406\u7684 comm\/footer \u90e8\u5206\uff0c\u4f1a\u5bf9\u5168\u5c40\u7684\u6570\u636e\u5bb9\u5668 globalDataHolder\u4e0e\u672c\u5730\u7684 data\u6570\u636e\u505a\u8fdb\u4e00\u6b65\u7684merge\u64cd\u4f5c\uff0c\u7136\u540e\u4e00\u540c\u4ea4\u7ed9\u4e0b\u4e00\u6b65\u7684\u6a21\u677f\u5904\u7406\u5f15\u64ceHanjst.<\/p>\n\n\n\n<p>\u8fd9\u4e2a\u901a\u9053\u53d6\u540d globalData\uff0c\u4e5f\u53c2\u8003\u4e86GWA2 PHP\u7684\u505a\u6cd5\uff0c\u6bd4\u5982\u5728PHP\u4e2d\uff0c\u4efb\u610f\u4ee3\u7801\u5757\u4e2d\uff0c\u53ef\u4ee5\u8bbf\u95ee\u5168\u5c40\u53d8\u91cf\uff0c\u4f7f\u7528\u5173\u952e\u5b57 global $myObject \uff0c\u610f\u601d\u662f\u73b0\u5728\u8981\u53bb\u8bfb\u53d6\u5168\u5c40\u53d8\u91cf $myObject \u8fd9\u4e2a\u5bf9\u8c61\u4e86( https:\/\/www.php.net\/manual\/en\/language.variables.scope.php )\u3002<br \/>GWA2 \u5957\u7cfb\uff08GWA2 PHP\uff0cGWA Perl, GWA2 Python, GWA2 Aspx\uff09\uff0c\u8de8\u8d8a\u591a\u4e2a\u7f16\u7a0b\u8bed\u8a00\uff0c\u4e5f\u5e0c\u671b\u80fd\u8d85\u8d8a\u5355\u4e2a\u8bed\u8a00\u9650\u5236\uff0c\u8d4b\u80fd\u8f6f\u4ef6\u7814\u53d1\uff0c\u63d0\u5347\u751f\u6210\u529b\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5f15\u7528\u7684\u4ee3\u7801\u5757\u53ef\u4ee5\u5728GWA2 \u7684\u9879\u76eeGitHub\u5e93\uff08 https:\/\/github.com\/wadelau\/GWA2 \uff09\u4e2d\u67e5\u9605\uff0c\u4e5f\u53ef\u4ee5\u5728 gitee\u4e0a\u7684GWA2\uff08 https:\/\/gitee.com\/xenxin\/GWA2 \uff09\u8bbf\u95ee\u5230\u3002<\/p>\n\n\n\n<p>\u5ba2\u6237\u95ee\u9053\uff1a\u66f4\u65b0\u5347\u7ea7\u540e\u7684 GWA2 Java \u8fd8\u6709bug\u6216\u6f0f\u6d1e\u5417\uff1f <br \/>\u8bda\u60f6\u8bda\u6050\u5730\uff0c\u6211\u4eec\u7684\u7b54\u6848\uff1a\u6ca1\u6709\u5df2\u77e5\u7684\u95ee\u9898\u4e86\u3002<br \/>\u54ea\u4e00\u4e2a GWA2 \u7684\u7248\u672c\u662f\u6700\u597d\u7684\uff1f <br \/>\u4e0b\u4e00\u4e2a\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator is-style-wide\" \/>\n\n\n\n<p>\u5168\u6587\u539f\u53d1\uff1a https:\/\/ufqi.com\/blog\/gwa2-java-multiple-threads-globaldata\/ \uff0c <strong><a rel=\"noreferrer noopener\" href=\"https:\/\/ufqi.com\/naturedns\/search?q=-R\/22SU\" target=\"_blank\">-R\/22SU<\/a><\/strong> <\/p>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2020\/08\/gwa2-logo-202005.v3.png\" alt=\"\" \/><figcaption>GWA2<\/figcaption><\/figure>\n\n\n\n<p><a href=\"https:\/\/ufqi.com\/dev\/gwa2\/\">-GWA2 \u5409\u5a03\u5154<\/a>&nbsp;\u662f\u201d\u901a\u7528\u7f51\u7edc\u5e94\u7528\u67b6\u6784( General Web Application Architeture,&nbsp;https:\/\/ufqi.com\/dev\/gwa2\/ )\u201d\uff0c\u57fa\u4e8e -GWA2 \u53ef\u4ee5\u8f7b\u4fbf\u6784\u5efa\u5404\u79cd\u7f51\u7edc\u5e94\u7528\u7a0b\u5e8f,<br \/>\u5305\u62ec\u590d\u6742\u7684\u5728\u7ebf\u8d2d\u7269\u5546\u57ce\u3001\u5728\u7ebf\u533b\u7597\u3001\u5728\u7ebf\u6559\u80b2\u3001 \u65c5\u6e38\u4ea4\u6613\u5e73\u53f0\u3001\u793e\u7fa4\u6216\u8005\u793e\u4ea4\u7f51\u7ad9\u548c\u65b0\u95fb\u8d44\u8baf\u7f51\u7ad9\u7b49\uff0c<br \/>\u4e5f\u5305\u62ec\u5404\u79cd\u4f01\u4e8b\u4e1a\u5355\u4f4d\u7f51\u4e0a\u95e8\u6237\uff0c\u5728\u7ebf\u4ea4\u4e92\u53ca\u670d\u52a1\u4f5c\u4e1a\u7cfb\u7edf\u7b49.<br \/>\u8fd8\u53ef\u4ee5\u5305\u62ec\u4e3aNativeApp\u505a\u670d\u52a1\u5668\u7aef\u652f\u6301, \u751a\u81f3\u662fWebApp\u7684\u5168\u90e8.<br \/>-GWA2 \u662f\u4e3a\u6570\u4e0d\u591a\u7684\u652f\u6301\u8de8\u5f00\u53d1\u8bed\u8a00\u7684\u5e94\u7528\u6846\u67b6\uff0c\u76ee\u524d\u652f\u6301 -Java, -PHP, -Perl, -Aspx and -Python .<\/p>\n\n\n\n<p>-GWA2 is a \u201cGeneral Web Application Architecture\u201d and based on -GWA2 developers can easily build a variety of network applications,<br \/>including complex online shopping malls, online medical services, online teaching, travel trading platforms, community or social networking sites and news information sites, etc.<br \/>Also the applications include various online portals of enterprises and institutions, online interaction and service operations systems.<br \/>Moreover it contains server-side support for Native App, or even all of the WebApp.<br \/>-GWA2 is one of the web frameworks which provide cross-language support for -Java, -PHP, -Perl, -Aspx and -Python at present.<\/p>\n\n\n\n<p><strong>-GWA2 is E.A.S.Y&nbsp;<\/strong><br \/><strong>Easy Along, Swift Yield<br \/><\/strong>\u8f7b\u677e\u542f\u52a8, \u5feb\u901f\u4ea7\u51fa.<\/p>\n\n\n\n<hr class=\"wp-block-separator\" \/>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2022\/01\/ufqifina-logo.png\"><img loading=\"lazy\" width=\"256\" height=\"256\" src=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2022\/01\/ufqifina-logo.png\" alt=\"\" class=\"wp-image-2724\" srcset=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2022\/01\/ufqifina-logo.png 256w, https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2022\/01\/ufqifina-logo-150x150.png 150w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/a><figcaption>\u6709\u798f\u91d1\u878dUfqiFina :  https:\/\/ufqi.com\/finance <\/figcaption><\/figure>\n\n\n\n<p>\u6709\u798f\u91d1\u878d \u662f\u4e00\u4e2a\u65e8\u5728\u4fc3\u8fdb\u8d22\u5bcc\u7a33\u6b65\u589e\u957f\u7684\u5de5\u5177\u5e73\u53f0\u3002<br \/>UfqiFina is a platform of tools designed to promote wealth growth steadily.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee4\u4e3e\u56fd\u6c11\u4f17\u9707\u60ca\u7684\u6c5f\u82cf\u5f90\u5dde\u4e30\u53bf\u94c1\u94fe\u5973\uff08\u751f\u80b2\u516b\u5b69\u5973\u5b50\uff09\u4e00\u4e8b\u9010\u6e10\u88ab\u6d88\u97f3\uff08 https: &hellip; <a href=\"https:\/\/ufqi.com\/blog\/gwa2-java-multiple-threads-globaldata\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":2759,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[42,6,2],"tags":[86,146,475,472,117,476,473],"_links":{"self":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/2758"}],"collection":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/comments?post=2758"}],"version-history":[{"count":12,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/2758\/revisions"}],"predecessor-version":[{"id":2773,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/2758\/revisions\/2773"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/media\/2759"}],"wp:attachment":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/media?parent=2758"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/categories?post=2758"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/tags?post=2758"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}