Swing


          天行健 君子以自強不息

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

          Java中取JVM中內存的方法

          Posted on 2008-04-18 14:10 zht 閱讀(679) 評論(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任務管理器的面板:
          主站蜘蛛池模板: 陆丰市| 铁岭县| 达尔| 迁西县| 江孜县| 阿荣旗| 上犹县| 长丰县| 乐安县| 博爱县| 鹤峰县| 临夏县| 富蕴县| 高要市| 新津县| 上高县| 邢台市| 元阳县| 鄄城县| 庆阳市| 建瓯市| 扎赉特旗| 通河县| 苍溪县| 依安县| 平舆县| 百色市| 历史| 长岛县| 平南县| 砚山县| 伊金霍洛旗| 思南县| 淳化县| 东兰县| 犍为县| 广东省| 金溪县| 肇东市| 景东| 华容县|