Swing


          天行健 君子以自強不息

          posts - 69, comments - 215, trackbacks - 0, articles - 16
             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          Java中取JVM中內存的方法

          Posted on 2008-04-18 14:10 zht 閱讀(683) 評論(4)  編輯  收藏 所屬分類: J2SE

            Runtime runtime = Runtime.getRuntime();
            long total = runtime.totalMemory();

            long free = runtime.freeMemory();
            System.out.println(total+"-"+free);


          totalMemory()
              /**
               * Returns the total amount of memory in the Java virtual machine.
               * The value returned by this method may vary over time, depending on
               * the host environment.
               * <p>
               * Note that the amount of memory required to hold an object of any
               * given type may be implementation-dependent.
               *
               * @return  the total amount of memory currently available for current
               *          and future objects, measured in bytes.
               */
          freeMemory()
              /**
               * Returns the amount of free memory in the Java Virtual Machine.
               * Calling the
               * <code>gc</code> method may result in increasing the value returned
               * by <code>freeMemory.</code>
               *
               * @return  an approximation to the total amount of memory currently
               *          available for future allocated objects, measured in bytes.
               */

          通過這個方法,可以寫一個類似于Windows任務管理器的面板:
          主站蜘蛛池模板: 永修县| 梁山县| 济南市| 托克逊县| 化州市| 崇义县| 同心县| 瑞安市| 南召县| 南澳县| 汕头市| 田阳县| 黄山市| 多伦县| 沧州市| 洛浦县| 合山市| 德清县| 二连浩特市| 新建县| 崇文区| 吉隆县| 溆浦县| 徐水县| 江北区| 阳曲县| 内乡县| 灵武市| 明光市| 浦县| 英超| 海林市| 保康县| 清镇市| 阿城市| 崇州市| 白朗县| 墨竹工卡县| 广宗县| 舟曲县| 宁陕县|