posts - 36,  comments - 88,  trackbacks - 0

  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任务管理器的面板:
posted on 2008-04-18 14:10 zht 阅读(35) 评论(0)  编辑  收藏 所属分类: J2SE

标题  
姓名  
主页
验证码 *  
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交