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任務管理器的面板:
          主站蜘蛛池模板: 大英县| 青冈县| 阿拉善右旗| 鲁山县| 会宁县| 南宁市| 宿迁市| 广宁县| 原平市| 河源市| 加查县| 彰化县| 长治市| 吕梁市| 谷城县| 上杭县| 揭阳市| 长寿区| 德昌县| 即墨市| 蕲春县| 洮南市| 安泽县| 苗栗市| 江永县| 屯留县| 八宿县| 大英县| 祁门县| 临夏县| 吴堡县| 灌南县| 濮阳市| 宣威市| 崇义县| 新泰市| 双柏县| 札达县| 沁源县| 曲周县| 兴山县|