What are GC roots for classes?

In Java, there are special objects called Garbage Collection Roots (GC roots). They serve as a root objects for Garbage Collection marking mechanism (see picture). This article describes four types of GC roots: local variables active threads static variables JNI references It is also mentioned, that: Classes themselves can be garbage-collected. GC roots aren't collected thus

GC的根源是什么?

在Java中,有一些称为垃圾收集根 (GC根)的特殊对象。 它们作为垃圾收集标记机制的根对象(见图片)。 本文介绍了四种类型的GC根源: 局部变量 活动线程 静态变量 JNI参考 还有人提到,那个: 课程本身可以被垃圾收集。 没有收集GC根,因此类本身不是GC根。 那么这些类的GC根源是什么? 那么这些类的GC根源是什么? Classloaders,有效地 - 通过其他GC根源。 如果没有任何东西能够到达类加载器 - 这意

Thread as a GC root

I have a question about GC roots. I read that on of GC roots is "Live thread". What does that mean? I always had impression that each thread has it's own stack and local variables of a stack are GC roots for thread and now I'm confused. What other types of object references, which are not on frame stack or native stack does thread representation have? Other question is doe

线程作为GC根

我有一个关于GC根源的问题。 我读到GC的根源是“Live thread”。 那是什么意思? 我总是有印象,每个线程都有自己的堆栈,堆栈的局部变量是线程的GC根,现在我很困惑。 线程表示具有哪些其他类型的对象引用,它们不在帧堆栈或本地堆栈上? 其他问题是年轻一代收集使用GC根源,还是仅用于主要算法? 谢谢 更新:好的抱歉,为了保持简单:我读过这篇简短的文章:yourkit.com/docs/java/help/gc_roots.jsp,并且有一个“Thre

What triggers the java Garbage Collector

I am a little confused to how garbage collection in Java works. I get that an object becomes eligible for garbage collection when there are no more live references to it, but what if it has references to live objects? Lets say i have a collection of nodes that again references more nodes List 1 -> Node a -> Node b 2 -> Node c -> Node d 3 -> Node d -> Node c 4 -> Node e 5

什么触发了Java垃圾收集器

我对Java中垃圾收集的工作方式有些困惑。 当没有更多实时引用时,我得到一个对象有资格进行垃圾回收,但如果它具有对活动对象的引用呢? 比方说,我有一个节点的集合,再次引用更多的节点 List 1 -> Node a -> Node b 2 -> Node c -> Node d 3 -> Node d -> Node c 4 -> Node e 5 现在如果我删除列表,节点cd和e应该被垃圾收集。 节点e不再有对它的引用,并且节点c和d具有循环引用。 但是Node a呢

Reading a plain text file in Java

It seems there are different ways to read and write data of files in Java. I want to read ASCII data from a file. What are the possible ways and their differences? ASCII is a TEXT file so you would use Readers for reading. Java also supports reading from a binary file using InputStreams. If the files being read are huge then you would want to use a BufferedReader on top of a FileReader to

用Java读取纯文本文件

看起来有不同的方法来读取和写入Java文件的数据。 我想从文件中读取ASCII数据。 什么是可能的方式和它们的区别? ASCII是一个TEXT文件,因此您可以使用读者进行阅读。 Java也支持使用InputStreams读取二进制文件。 如果正在读取的文件很大,那么您会希望在FileReader上使用BufferedReader来提高读取性能。 阅读这篇关于如何使用Reader的文章 我还建议你下载并阅读这本叫做Thinking In Java的精彩(但免费)书 在Jav

Easiest way to convert a List to a Set in Java

在Java中将List转换为Set的最简单方法是什么? Set<Foo> foo = new HashSet<Foo>(myList); I agree with sepp2k, but there are some other details that might matter: new HashSet<Foo>(myList); will give you an unsorted set which doesn't have duplicates. In this case, duplication is identified using the .equals() method on your objects. This is done in combination with the .hashCo

在Java中将List转换为Set的最简单方法

在Java中将List转换为Set的最简单方法是什么? Set<Foo> foo = new HashSet<Foo>(myList); 我同意sepp2k,但还有一些其他细节可能很重要: new HashSet<Foo>(myList); 会给你一个没有重复的未排序集合。 在这种情况下,使用对象上的.equals()方法识别重复。 这与.hashCode()方法结合使用。 (关于平等的更多信息请看这里) 给出排序集的替代方法是: new TreeSet<Foo>(myList); 如果Foo实

How can I concatenate two arrays in Java?

I need to concatenate two String arrays in Java. void f(String[] first, String[] second) { String[] both = ??? } What is the easiest way to do this? I found a one-line solution from the good old Apache Commons Lang library. ArrayUtils.addAll(T[], T...) Code: String[] both = (String[])ArrayUtils.addAll(first, second); Here's a simple method that will concatenate two arrays and re

我怎样才能在Java中连接两个数组?

我需要在Java中连接两个字符串数组。 void f(String[] first, String[] second) { String[] both = ??? } 什么是最简单的方法来做到这一点? 我从老的Apache Commons Lang库中找到了一个单线解决方案。 ArrayUtils.addAll(T[], T...) 码: String[] both = (String[])ArrayUtils.addAll(first, second); 这是一个简单的方法,它将连接两个数组并返回结果: public <T> T[] concatenate(T[] a, T[] b) {

Java process memory usage keeps increasing infinitely

Preconditions: PC with 16 Gb of RAM JDK 1.8.x installed on Ubuntu 16.10 x64. a standard Spring-based web application, that is deployed on Tomcat 8.5.x. Tomcat is configured with next parameters: CATALINA_OPTS="$CATALINA_OPTS -Xms128m -Xmx512m -XX:NewSize=64m -XX:MaxNewSize=128m -Xss512k -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods -XX:MaxMetaspaceSize=512m -XX:-T

Java进程内存使用量无限增加

前提条件: 带有16 Gb RAM的PC JDK 1.8.x安装在Ubuntu 16.10 x64上。 一个标准的基于Spring的Web应用程序,部署在Tomcat 8.5.x上。 Tomcat配置有下列参数: CATALINA_OPTS="$CATALINA_OPTS -Xms128m -Xmx512m -XX:NewSize=64m -XX:MaxNewSize=128m -Xss512k -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods -XX:MaxMetaspaceSize=512m -XX:-TieredCompilation -XX:ReservedCodeCacheSize=512m&

heap memory usage as a Java program runs

I have a simple code for a multi-threaded echo server in Java (it returns whatever received back to the clients). I'm profiling the various resources including the non-heap memory usage. I understand the non-heap memory of JVM is also created at the JVM start-up, however, stores per-class structures and includes call stacks, memory allocated by native code for instance for off-heap caching,

堆内存使用情况作为Java程序运行

我有一个简单的代码用于Java中的多线程回显服务器(它将返回的任何内容返回给客户端)。 我正在分析各种资源,包括非堆内存使用情况。 我知道JVM的非堆内存也是在JVM启动时创建的,但是,它存储每类结构并包含调用堆栈,由本机代码分配的内存,例如用于离堆缓存,Metaspace以及内存由JIT编译器使用(编译的本机代码)。 但我有两个主要问题: 1)随着时间的推移,非堆内存使用率会稍微增加。 这个增长很小,但是这会导致内

Big difference between JVM process size and Memory Heap size

I am developing java swing application on Windows 8.1 64bit with 4GB RAM with JDK version 8u20 64bit. The problem is when I launched the application with Netbeans profiler with Monitor option. When the first Jframe is loaded the application Memory Heap is around 18mb and the JVM process size around 50mb (image1) . Then when I launch the other Jframe which contains a JFxPanel with webView th

JVM进程大小和内存堆大小之间的巨大差异

我正在Windows 8.1 64位上开发带有JDK 8u20 64bit 4GB RAM的java swing应用程序。 问题是当我使用Monitor选项启动Netbeans分析器的应用程序时。 当加载第一个Jframe时,应用程序内存堆大约为18mb ,JVM进程大小约为50mb(image1) 。 然后,当我启动另一个包含带有WebView的JFxPanel的Jframe时,堆跳到45mb ,JVM 进程跳到700mb非常快(image2) ,这非常混乱。 然后,当关闭第二个JFrame并将其丢弃并调用System.gc(),

Non heap memory and No of loaded classes keeps on increasing

We are doing a performance test of our application. During the test, we find that non heap memory and total no of loaded classes keeps on increasing over the time. Our guess is probably some 3rd party jar or application code is leaking. What are the best ways to find such leak or pin point the problem ? Any tools which can help me to find the rootcause ? We are using Jboss EAP 6.1. Make

非堆内存和加载类的数量不断增加

我们正在对我们的应用程序进行性能测试。 在测试过程中,我们发现非堆内存和加载类总数不断增加。 我们的猜测可能是某些第三方jar或应用程序代码泄漏。 什么是最好的方法来找到这种泄漏或针指出问题? 任何可以帮助我找到根源的工具? 我们正在使用Jboss EAP 6.1。 通过JDK的jvisualVm首先进行堆转储,并使用内存分析器(MAT)进行分析。 然后在标题'Non-Heap'中看到这个方向:http://www.yourkit.com/ 这