Why does idle Java application generate 20 MB garbage in 4 minutes?

I was testing performance of Guava cache by loading 5000 objects in cache using 50 threads using ExecutorService. I wanted to see the heap occupied by the cached objects. It looked as though the cached objects were eating up 25MB. Later, I put a Thread.sleep on the main thread to sleep the application for 10 minutes, so that I could sample the memory etc. Surprisingly, even when the applic

为什么空闲Java应用程序在4分钟内生成20 MB垃圾?

我使用ExecutorService通过使用50个线程在缓存中加载5000个对象来测试Guava缓存的性能。 我想看看被缓存的对象占用的堆。 它看起来好像缓存的对象吃了25MB。 后来,我在主线程中放置了一个Thread.sleep,让应用程序休眠10分钟,以便我可以对内存进行采样等。 令人惊讶的是,即使应用程序处于睡眠状态,它也会每4分钟产生20MB的垃圾。 由于每4分钟有一次GC操作,因此在使用的堆图中会看到一个锯齿波。 为什么java在空闲

VisualVM: Ideal Heap Memory Usage Graph

I am monitoring my Java application (written in JDK 1.7 ) using VisualVM . Following is the graph that shows heap memory usage for the duration that this application ran. Looking at this graph ones see that there are a lot of spikes in it. These spikes indicate creation of objects by the application. Once the application is done with them it destroys them using gc (implicitly called in this

VisualVM:理想的堆内存使用情况图

我使用VisualVM监视我的Java应用程序(用JDK 1.7编写)。 以下是显示此应用程序运行期间的堆内存使用情况的图表。 看这张图看到它有很多尖峰。 这些尖峰表示应用程序创建对象。 一旦应用程序完成后,它会使用gc破坏它们(在本例中隐式调用)。 此外,这是应用程序仍在运行时内存分析器的屏幕截图 对我来说,图的向上和向下性表明java对象的有效使用。 这个推论是否正确? 人们应该瞄准的堆使用图的理想性质是什么?

VisualVM : Comparing performance of two version of same application

I have refactored and tuned my java application. I now want to compare the performance of newer and older version of the application , in terms of their individual CPU and heap memory usage. I am using VisualVM and JDK 1.7 . I run them individually and monitor them using VisualVM. At the end all i have is two sets of graphs. This makes deciding which one is better difficult. Is there a m

VisualVM:比较两个版本的相同应用程序的性能

我重构并调整了我的Java应用程序。 我现在想根据它们各自的CPU和堆内存使用情况比较新版本和旧版本应用程序的性能。 我正在使用VisualVM和JDK 1.7 。 我分别运行它们并使用VisualVM监视它们。 最后,我有两套图表。 这使得决定哪一个更困难。 是否有VisualVm提供的度量标准,它可以决定哪个版本更容易执行。 ?。 像使用的平均CPU或平均堆使用(如果这是一种测量性能的准确方法)谢谢! 平台MBean提供对CPU,内存

How do I start VisualVM with the JMXWS WS Connector (JSR

I have an Java application running in JBoss in which I have enabled JMX remote monitoring. This allows me to connect with tools such as jconsole and visualvm to monitor memory usage, cpu utilization, mbeans, and more. The server on which my application is running has restrictive port access though, which is why I am using the JSR-262 JMX WS Connector. The JSR-262 implementation has an example

如何使用JMXWS WS连接器(JSR)启动VisualVM

我有一个运行在JBoss中的Java应用程序,其中启用了JMX远程监控。 这使我可以连接诸如jconsole和visualvm等工具来监视内存使用情况,CPU利用率,mbeans等等。 尽管运行我的应用程序的服务器具有限制性端口访问权限,这就是我使用JSR-262 JMX WS Connector的原因。 JSR-262实现有一个示例,说明如何为jconsole启用jmx:ws协议。 但我想尝试visualvm相同。 我相信我必须做的是,启动visualvm时: 向类路径添加一些额外的JS

Bug in eclipse compiler or in javac ("type parameters of T cannot be determined")

The following code public class GenericsTest2 { public static void main(String[] args) throws Exception { Integer i = readObject(args[0]); System.out.println(i); } public static <T> T readObject(String file) throws Exception { return readObject(new ObjectInputStream(new FileInputStream(file))); // closing the stream in finally removed to get a

eclipse编译器或javac中的错误(“T的类型参数无法确定”)

下面的代码 public class GenericsTest2 { public static void main(String[] args) throws Exception { Integer i = readObject(args[0]); System.out.println(i); } public static <T> T readObject(String file) throws Exception { return readObject(new ObjectInputStream(new FileInputStream(file))); // closing the stream in finally removed to get a small ex

Stack with find

I am interested in creating a Java data structure similar to a stack that supports the following operations as efficiently as possible: Push, which adds a new element atop the stack, Pop, which removes the top element of the stack, Find-Max, which returns (but does not remove) the largest element of the stack, and Find-Min, which returns (but does not remove) the smallest element of the s

与查找堆叠

我有兴趣创建一个类似于支持以下操作的堆栈的Java数据结构,尽可能高效: Push,在堆栈顶部添加一个新元素, Pop,删除堆栈的顶层元素, Find-Max,它返回(但不删除)堆栈的最大元素,并且 Find-Min,返回(但不删除)堆栈的最小元素,以及 这个数据结构的最快实现是什么? 我该如何去用Java编写它? 这是一个经典的数据结构问题。 问题背后的直觉如下 - 最大值和最小值可以改变的唯一方式是如果您将新值推入堆栈

How do I monitor the computer's CPU, memory, and disk usage in Java?

I would like to monitor the following system information in Java: Current CPU usage** (percent) Available memory* (free/total) Available disk space (free/total) *Note that I mean overall memory available to the whole system, not just the JVM. I'm looking for a cross-platform solution (Linux, Mac, and Windows) that doesn't rely on my own code calling external programs or using JN

如何在Java中监视计算机的CPU,内存和磁盘使用情况?

我想在Java中监视以下系统信息: 当前CPU使用率**(百分比) 可用内存*(免费/总计) 可用磁盘空间(免费/总计) *请注意,我的意思是整个系统可用的全部内存,而不仅仅是JVM。 我正在寻找一种不依赖我自己的调用外部程序或使用JNI的代码的跨平台解决方案(Linux,Mac和Windows)。 虽然这些都是可行的选择,但如果有人已经有了更好的解决方案,我宁愿不自己维护操作系统特定的代码。 如果有一个免费的库以可靠的,

Objects created inside a method

I was wondering where objects instantiated inside a local method stored? As far as my knowledge goes, objects are stored in the heap, and their references are stored in the stack. If so, then when the function returns,and the reference to the object no longer exists (since the local stack frame of the function is popped), does the object stay in the heap, or do we have to delete it manually (or

在方法内创建的对象

我想知道在本地方法内部实例化对象存储? 就我所知,对象存储在堆中,并且它们的引用存储在堆栈中。 如果是这样,那么当函数返回时,对该对象的引用不再存在(因为函数的本地堆栈框架被弹出),该对象是否留在堆中,还是我们必须手动删除它(或使用垃圾收集,如在Java中)? 这取决于你打算如何处理这个对象,如果你返回对象,那么它的生命周期就会延长。 如果您将其创建为临时,那么会有两种可能的结果。 如果你用new创

Difference between static block and assigning static in class?

Is there any difference between following two initializations of static variables: class Class1 { private static Var var; static { var = getSingletonVar(); } } class Class2 { private static var = getSingletonVar; } Are these two different ways of initializing a static variable functionally the same? Yes, its functionally the same. From Java doc There is an al

在课堂上静态块和分配静态之间的区别?

以下两个初始化静态变量之间是否有区别: class Class1 { private static Var var; static { var = getSingletonVar(); } } class Class2 { private static var = getSingletonVar; } 这两种初始化静态变量的方法在功能上是相同的吗? 是的,它的功能是一样的。 从Java文档 There is an alternative to static blocks — you can write a private static method: class Whatever { pub

Is there a way to list the java version of all my maven dependencies?

Consider I have a maven java project that I wish to use the minimum version of Java possible. It has a number of dependencies. Is there a way I can see what the version of java used to compile the jar is for all of the resolved dependencies? If you run mvn site on your project, one of the default reports (the 'Dependencies' report) generated will give you details about your dependenci

有没有办法列出我所有的Maven依赖关系的Java版本?

考虑我有一个maven java项目,我希望使用Java的最低版本。 它有一些依赖关系。 有没有一种方法可以看到用于编译jar的java版本是否适用于所有已解决的依赖关系? 如果您在项目上运行mvn site ,则生成的其中一个默认报告(“依赖关系”报告)会为您提供有关您的依赖关系的详细信息。 运行mvn site找到target/site/dependencies.html文件并在浏览器中打开它。 标题为“依赖文件详细信息”的部分有一个表格,其中一列是用于编译