{"id":993,"date":"2018-09-17T19:06:49","date_gmt":"2018-09-17T10:06:49","guid":{"rendered":"https:\/\/chat-messenger.com\/?p=993"},"modified":"2019-06-30T18:44:15","modified_gmt":"2019-06-30T09:44:15","slug":"%e0%a4%b0%e0%a4%a8%e0%a4%9f%e0%a4%be%e0%a4%87%e0%a4%ae-%e0%a4%9f%e0%a5%8b%e0%a4%9f%e0%a4%b2%e0%a4%ae%e0%a5%87%e0%a4%ae%e0%a5%8b%e0%a4%b0%e0%a5%80-%e0%a4%ab%e0%a5%8d%e0%a4%b0%e0%a5%80%e0%a4%ae%e0%a5%87","status":"publish","type":"post","link":"https:\/\/chat-messenger.com\/hi\/blog\/java\/runtime-totalmemory-freememory","title":{"rendered":"\u091c\u093e\u0935\u093e \u092e\u0947\u092e\u094b\u0930\u0940 \u0909\u092a\u092f\u094b\u0917 \u092a\u094d\u0930\u093e\u092a\u094d\u0924 \u0915\u0930\u0947\u0902"},"content":{"rendered":"<h2 class=\"common_title\"><a name=\"0\">\u091c\u093e\u0935\u093e <strong>\u092f\u093e\u0926<\/strong>\u0909\u092a\u092f\u094b\u0917 \u0938\u0902\u092c\u0902\u0927\u0940 \u0921\u0947\u091f\u093e \u092a\u094d\u0930\u093e\u092a\u094d\u0924 \u0915\u0930\u0947\u0902 <strong>Runtime.getRuntime().totalMemory, freeMemory<\/strong><\/a><\/h2>\n<p>\n<strong>\u091c\u093e\u0935\u093e <\/strong> \u092f\u0939 \u092b\u093c\u0902\u0915\u094d\u0936\u0928 \u0935\u0930\u094d\u091a\u0941\u0905\u0932 \u092e\u0936\u0940\u0928 \u0915\u0940 \u092e\u0947\u092e\u094b\u0930\u0940 \u0915\u0947 \u092c\u093e\u0930\u0947 \u092e\u0947\u0902 \u091c\u093e\u0928\u0915\u093e\u0930\u0940 \u0926\u0947\u0924\u093e \u0939\u0948, \u091c\u093f\u0938\u092e\u0947\u0902 &quot;\u0915\u0941\u0932&quot;, &quot;\u0909\u092a\u092f\u094b\u0917 \u0915\u0940 \u0917\u0908&quot; \u0914\u0930 &quot;\u0905\u0927\u093f\u0915\u0924\u092e \u0909\u092a\u0932\u092c\u094d\u0927&quot; \u0936\u093e\u092e\u093f\u0932 \u0939\u0948\u0902\u0964<br \/>\n\u092a\u094d\u0930\u0924\u094d\u092f\u0947\u0915 \u0906\u0907\u091f\u092e \u0915\u093e \u0938\u094d\u092a\u0937\u094d\u091f\u0940\u0915\u0930\u0923 \u0907\u0938 \u092a\u094d\u0930\u0915\u093e\u0930 \u0939\u0948:\n<\/p>\n<ul>\n<li><strong>\u0915\u0941\u0932<\/strong>\u30fb\u30fb\u30fb<strong>\u0930\u0928\u091f\u093e\u0907\u092e.\u0917\u0947\u091f\u0930\u0928\u091f\u093e\u0907\u092e().\u091f\u094b\u091f\u0932\u092e\u0947\u092e\u094b\u0930\u0940()<\/strong>\u092f\u0939 \u091c\u093e\u0935\u093e \u0935\u0930\u094d\u091a\u0941\u0905\u0932 \u092e\u0936\u0940\u0928 \u0915\u094b \u0906\u0935\u0902\u091f\u093f\u0924 \u092e\u0947\u092e\u094b\u0930\u0940 \u0915\u0940 \u092e\u093e\u0924\u094d\u0930\u093e \u0939\u0948\u0964<\/li>\n<li><strong>\u0909\u092a\u092f\u094b\u0917 \u0915\u0940 \u092e\u093e\u0924\u094d\u0930\u093e<\/strong>\u30fb\u30fb\u30fb<strong>\u0930\u0928\u091f\u093e\u0907\u092e.\u0917\u0947\u091f\u0930\u0928\u091f\u093e\u0907\u092e().\u091f\u094b\u091f\u0932\u092e\u0947\u092e\u094b\u0930\u0940()<\/strong>\u3000-\u3000<strong>Runtime.getRuntime().freeMemory()<\/strong>\u092f\u0947 \u092c\u0928 \u0917\u092f\u093e,<br \/>\n\u092f\u0939 \u092e\u0947\u092e\u094b\u0930\u0940 \u092e\u0947\u0902 \u0935\u0930\u094d\u0924\u092e\u093e\u0928 \u092e\u0947\u0902 \u0906\u0935\u0902\u091f\u093f\u0924 \u0911\u092c\u094d\u091c\u0947\u0915\u094d\u091f\u094d\u0938 \u0926\u094d\u0935\u093e\u0930\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0940 \u0917\u0908 \u092e\u0947\u092e\u094b\u0930\u0940 \u0939\u0948\u0964<\/li>\n<li><strong>\u0905\u0927\u093f\u0915\u0924\u092e \u0909\u092a\u092f\u094b\u0917 \u092f\u094b\u0917\u094d\u092f<\/strong>\u30fb\u30fb\u30fb<strong>Runtime.getRuntime().maxMemory()<\/strong>\u092f\u0939 \u091c\u093e\u0935\u093e \u0935\u0930\u094d\u091a\u0941\u0905\u0932 \u092e\u0936\u0940\u0928 \u0926\u094d\u0935\u093e\u0930\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0940 \u091c\u093e\u0928\u0947 \u0935\u093e\u0932\u0940 \u092e\u0947\u092e\u094b\u0930\u0940 \u0915\u0940 \u0905\u0927\u093f\u0915\u0924\u092e \u092e\u093e\u0924\u094d\u0930\u093e \u0915\u094b \u0926\u0930\u094d\u0936\u093e\u0924\u093e \u0939\u0948\u0964<br \/>\n\u091c\u092c \u092e\u0947\u092e\u094b\u0930\u0940 \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0941\u0932 \u0938\u0940\u092e\u093e \u0915\u0947 \u0915\u0930\u0940\u092c \u092a\u0939\u0941\u0902\u091a \u091c\u093e\u0924\u093e \u0939\u0948 \u0914\u0930 \u0917\u093e\u0930\u094d\u092c\u0947\u091c \u0915\u0932\u0947\u0915\u094d\u0936\u0928 \u092e\u0947\u092e\u094b\u0930\u0940 \u0915\u094b \u0916\u093e\u0932\u0940 \u0928\u0939\u0940\u0902 \u0915\u0930 \u092a\u093e\u0924\u093e \u0939\u0948, \u0924\u094b \u091c\u093e\u0935\u093e \u0935\u0930\u094d\u091a\u0941\u0905\u0932 \u092e\u0936\u0940\u0928 &quot;\u0905\u0927\u093f\u0915\u0924\u092e \u0909\u092a\u0932\u092c\u094d\u0927&quot; \u092e\u093e\u0924\u094d\u0930\u093e \u0924\u0915 \u0935\u093f\u0938\u094d\u0924\u093e\u0930\u093f\u0924 \u0939\u094b \u091c\u093e\u0924\u0940 \u0939\u0948\u0964<\/li>\n<\/ul>\n<h2 class=\"common_title\"><a name=\"1\">\u0928\u092e\u0942\u0928\u093e \u0915\u093e\u0930\u094d\u092f\u0915\u094d\u0930\u092e<\/a><\/h2>\n<pre class=\"sample_src\">\/**\r\n * Java \u4eee\u60f3\u30de\u30b7\u30f3\u306e\u30e1\u30e2\u30ea\u7dcf\u5bb9\u91cf\u3001\u4f7f\u7528\u91cf\u3001\r\n * \u4f7f\u7528\u3092\u8a66\u307f\u308b\u6700\u5927\u30e1\u30e2\u30ea\u5bb9\u91cf\u306e\u60c5\u5831\u3092\u8fd4\u3057\u307e\u3059\u3002\r\n * @return Java \u4eee\u60f3\u30de\u30b7\u30f3\u306e\u30e1\u30e2\u30ea\u60c5\u5831\r\n *\/\r\npublic static String getMemoryInfo() {\r\n    DecimalFormat f1 = new DecimalFormat(\"#,###KB\");\r\n    DecimalFormat f2 = new DecimalFormat(\"##.#\");\r\n    long free = Runtime.getRuntime().freeMemory() \/ 1024;\r\n    long total = Runtime.getRuntime().totalMemory() \/ 1024;\r\n    long max = Runtime.getRuntime().maxMemory() \/ 1024;\r\n    long used = total - free;\r\n    double ratio = (used * 100 \/ (double)total);\r\n    String info = \r\n    \"Java \u30e1\u30e2\u30ea\u60c5\u5831 : \u5408\u8a08=\" + f1.format(total) + \"\u3001\" +\r\n    \"\u4f7f\u7528\u91cf=\" + f1.format(used) + \" (\" + f2.format(ratio) + \"%)\u3001\" +\r\n    \"\u4f7f\u7528\u53ef\u80fd\u6700\u5927=\"+f1.format(max);\r\n    return info;\r\n}\r\n<\/pre>\n<p><script type=\"text\/javascript\" src=\"https:\/\/chat-messenger.com\/js\/common.js?dd12sssas2223\" charset=\"UTF-8\"><\/script><br \/>\n<script type=\"text\/javascript\"> writePR(); <\/script><\/p>\n<h2 class=\"common_title\"><a name=\"2\">\u0928\u093f\u0937\u094d\u092a\u093e\u0926\u0928 \u092a\u0930\u093f\u0923\u093e\u092e 1<\/a><\/h2>\n<p>\u25c6\u0909\u0926\u093e\u0939\u0930\u0923<\/p>\n<pre class=\"sample_src\">public static void main(String[] args) { System.out.println(getMemoryInfo()); }\r\n<\/pre>\n<p>\u25c6\u0906\u0909\u091f\u092a\u0941\u091f \u092a\u0930\u093f\u0923\u093e\u092e<\/p>\n<pre class=\"console\">\u091c\u093e\u0935\u093e \u092e\u0947\u092e\u094b\u0930\u0940 \u0938\u0902\u092c\u0902\u0927\u0940 \u091c\u093e\u0928\u0915\u093e\u0930\u0940: \u0915\u0941\u0932 = 1,984KB, \u0909\u092a\u092f\u094b\u0917 \u0915\u093f\u092f\u093e \u0917\u092f\u093e = 458KB (23.1%), \u0905\u0927\u093f\u0915\u0924\u092e \u0909\u092a\u0932\u092c\u094d\u0927 = 65,088KB\r\n<\/pre>\n<h2 class=\"common_title\"><a name=\"3\">\u0928\u093f\u0937\u094d\u092a\u093e\u0926\u0928 \u092a\u0930\u093f\u0923\u093e\u092e 2<\/a><\/h2>\n<p>\u25c6\u0909\u0926\u093e\u0939\u0930\u0923<br \/>\n\u091c\u093e\u0935\u093e \u0939\u0940\u092a \u0938\u093e\u0907\u091c \u0915\u094b \u092c\u0926\u0932\u0915\u0930 \u092a\u094d\u0930\u094b\u0917\u094d\u0930\u093e\u092e \u091a\u0932\u093e\u0928\u0947 \u0915\u093e \u092a\u094d\u0930\u092f\u093e\u0938 \u0915\u0930\u0947\u0902\u0964<br \/>\n\u091c\u093e\u0935\u093e \u0915\u092e\u093e\u0902\u0921 \u0935\u093f\u0915\u0932\u094d\u092a\u094b\u0902 \u0915\u093e \u0909\u092a\u092f\u094b\u0917 \u0915\u0930\u0915\u0947 \u091c\u093e\u0935\u093e \u0939\u0940\u092a \u0906\u0915\u093e\u0930 \u0928\u093f\u0930\u094d\u0926\u093f\u0937\u094d\u091f \u0915\u093f\u092f\u093e \u091c\u093e \u0938\u0915\u0924\u093e \u0939\u0948\u0964<\/p>\n<div class=\"point\">\n\u091c\u093e\u0935\u093e -Xms64m -Xmx512m \u092e\u0941\u0916\u094d\u092f <\/p>\n<p>-Xms \u092a\u094d\u0930\u093e\u0930\u0902\u092d\u093f\u0915 \u0939\u0940\u092a \u0906\u0915\u093e\u0930<br \/>\n\u091c\u093e\u0935\u093e \u0935\u0930\u094d\u091a\u0941\u0905\u0932 \u092e\u0936\u0940\u0928 \u0915\u0947 \u0932\u093f\u090f \u092a\u094d\u0930\u093e\u0930\u0902\u092d\u093f\u0915 \u092e\u0947\u092e\u094b\u0930\u0940 \u0906\u0935\u0902\u091f\u0928 \u0928\u093f\u0930\u094d\u0926\u093f\u0937\u094d\u091f \u0915\u0930\u0924\u093e \u0939\u0948\u0964 \u0921\u093f\u092b\u093c\u0949\u0932\u094d\u091f \u092e\u093e\u0928 2MB \u0939\u0948\u0964<br \/>\n-Xmx \u0905\u0927\u093f\u0915\u0924\u092e \u0939\u0940\u092a \u0906\u0915\u093e\u0930<br \/>\n\u091c\u093e\u0935\u093e \u0935\u0930\u094d\u091a\u0941\u0905\u0932 \u092e\u0936\u0940\u0928 \u0915\u094b \u0906\u0935\u0902\u091f\u093f\u0924 \u0915\u0940 \u091c\u093e\u0928\u0947 \u0935\u093e\u0932\u0940 \u092e\u0947\u092e\u094b\u0930\u0940 \u0915\u0940 \u0905\u0927\u093f\u0915\u0924\u092e \u092e\u093e\u0924\u094d\u0930\u093e \u0928\u093f\u0930\u094d\u0926\u093f\u0937\u094d\u091f \u0915\u0930\u0924\u093e \u0939\u0948\u0964 \u0921\u093f\u092b\u093c\u0949\u0932\u094d\u091f \u092e\u093e\u0928 64MB \u0939\u0948\u0964\n<\/div>\n\n<pre class=\"sample_src\">public static void main(String[] args) { System.out.println(getMemoryInfo()); }\r\n<\/pre>\n<p>\u25c6\u0906\u0909\u091f\u092a\u0941\u091f \u092a\u0930\u093f\u0923\u093e\u092e<\/p>\n<pre class=\"console\">\u091c\u093e\u0935\u093e \u092e\u0947\u092e\u094b\u0930\u0940 \u0938\u0902\u092c\u0902\u0927\u0940 \u091c\u093e\u0928\u0915\u093e\u0930\u0940: \u0915\u0941\u0932 = 65,088KB, \u0909\u092a\u092f\u094b\u0917 \u0915\u093f\u092f\u093e \u0917\u092f\u093e = 524KB (0.8%), \u0905\u0927\u093f\u0915\u0924\u092e \u0909\u092a\u0932\u092c\u094d\u0927 = 520,256KB\r\n<\/pre>\n<p>&quot;\u0915\u0941\u0932 \u0930\u0928\u091f\u093e\u0907\u092e.getRuntime().totalMemory()&quot;<strong>-\u090f\u0915\u094d\u0938\u090f\u092e\u090f\u0938<\/strong>\u0905\u0927\u093f\u0915\u0924\u092e \u0909\u092a\u0932\u092c\u094d\u0927 \u092e\u093e\u0928 Runtime.getRuntime().maxMemory() \u0939\u0948\u0964<strong>-\u090f\u0915\u094d\u0938\u090f\u092e\u090f\u0915\u094d\u0938<\/strong>\u092f\u0939 \u0932\u093f\u0902\u0915 [\u0938\u0902\u092c\u0902\u0927\u093f\u0924 \u092a\u0943\u0937\u094d\u0920] \u092a\u0930 \u0932\u0947 \u091c\u093e\u0924\u093e \u0939\u0948\u0964<\/p>","protected":false},"excerpt":{"rendered":"<p>Java \u30e1\u30e2\u30ea\u30fc\u4f7f\u7528\u91cf\u3092\u53d6\u5f97 Runtime.getRuntime().totalMemory\u3001freeMe [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[19],"tags":[],"class_list":["post-993","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/chat-messenger.com\/hi\/wp-json\/wp\/v2\/posts\/993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chat-messenger.com\/hi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chat-messenger.com\/hi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/hi\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/chat-messenger.com\/hi\/wp-json\/wp\/v2\/comments?post=993"}],"version-history":[{"count":9,"href":"https:\/\/chat-messenger.com\/hi\/wp-json\/wp\/v2\/posts\/993\/revisions"}],"predecessor-version":[{"id":3636,"href":"https:\/\/chat-messenger.com\/hi\/wp-json\/wp\/v2\/posts\/993\/revisions\/3636"}],"wp:attachment":[{"href":"https:\/\/chat-messenger.com\/hi\/wp-json\/wp\/v2\/media?parent=993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chat-messenger.com\/hi\/wp-json\/wp\/v2\/categories?post=993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chat-messenger.com\/hi\/wp-json\/wp\/v2\/tags?post=993"}],"curies":[{"name":"\u0921\u092c\u094d\u0932\u094d\u092f\u0942\u092a\u0940","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}