在Java中,是否可以增加JVM的可用内存和/或杀死其他Java程序? [英] In Java, is it possible to increase the JVM's available memory and/or kill other Java programs?

查看:229
本文介绍了在Java中,是否可以增加JVM的可用内存和/或杀死其他Java程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对高级Java缺乏经验,所以请耐心等待。

I'm inexperienced with advanced Java so please bear with me.

我很好奇Java能够实现可能被称为自主的功能。假设我们有两个Java程序在运行。并且一个程序确定另一个程序正在占用内存,从而杀死该程序和/或为JVM分配更多内存。

I'm curious about Java's ability to implement features that may be termed "autonomic". Say we have two Java programs running. And one program determines that the other one is hogging memory, and thus kills that program and/or allocates more memory to the JVM.

我在Java中知道你可以看到什么可用内存是(请参阅如何操作检查Java中的CPU和内存使用情况?),但如果我们想深入挖掘怎么办?

I know in Java you can see what the available memory is (see How to do I check CPU and Memory Usage in Java?), but what if we want to dig deeper?

谢谢。

推荐答案


您问: - 是否有可能增加JVM的可用内存和/或杀死其他Java程序?

You Asked:-is it possible to increase the JVM's available memory and/or kill other Java programs?




  1. 是可能您可以增加 jvm的堆大小喜欢:

      java -Xmx512M ClassName //512M = memory you want to increase


  • 要杀死以下流程: taskkill / F / IM< processname> .exe

    注意

    - >但这不是一个好主意,因为堆可能是固定大小的,也可能根据垃圾收集器的策略进行扩展。


    - >打开命令提示符,键入 taskkill /?以了解详细信息。

    3。您可以检查当前由 jvm 保留的总内存可用内存最大内存以这种方式

    3 . And You can check total memory , free memory and max memory currently reserved by jvm in this way.

              int  MegaBytes = 1024*1024 ;
    
              long  freeMemory = Runtime.getRuntime().freeMemory() / MegaBytes;
              long  totalMemory = Runtime.getRuntime().totalMemory() / MegaBytes;
              long  maxMemory = Runtime.getRuntime().maxMemory() / MegaBytes;
    
              System.out.println("Memory used by JVM: " + (maxMemory - freeMemory));
              System.out.println("freeMemory in JVM: " + freeMemory);
              System.out.println("totalMemory in JVM : " + totalMemory);
              System.out.println("maxMemory in JVM: " + maxMemory);
    

    更多信息请点击此处

    这篇关于在Java中,是否可以增加JVM的可用内存和/或杀死其他Java程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆