Swing


          天行健 君子以自強不息

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

          Java中取JVM中內存的方法

          Posted on 2008-04-18 14:10 zht 閱讀(684) 評論(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任務管理器的面板:
          主站蜘蛛池模板: 乐安县| 瑞金市| 桂东县| 渑池县| 施甸县| 新闻| 永康市| 新安县| 阜新市| 仁化县| 卓尼县| 东城区| 稷山县| 布尔津县| 北川| 任丘市| 屯门区| 道孚县| 镇坪县| 灵川县| 永嘉县| 台中市| 治多县| 巴南区| 栾城县| 陆川县| 高平市| 黄冈市| 专栏| 海伦市| 若尔盖县| 黄浦区| 齐河县| 镇安县| 阳泉市| 微山县| 会理县| 青海省| 鄂托克旗| 宜丰县| 乐陵市|