简体   繁体   English

Java finalize方法,SocksSocketImpl,Profiling等

[英]Java finalize method ,SocksSocketImpl, Profiling and others

We have a batch job, that reads data from database and writes it to a file. 我们有一个批处理作业,它从数据库中读取数据并将其写入文件。 The job is written on top of Spring Batch 2.8. 该作业是在Spring Batch 2.8之上编写的。 We have noticed, it's taking a lot of memory and are trying to tune it. 我们已经注意到,它占用了大量内存,并且正在尝试对其进行调整。 I have some questions while performing the exercise 我在练习时有一些疑问

  1. I know implementing finalize() is not recommended. 我知道不建议实现finalize()。 In numerous posts I have read - they say the object might be pushed to a ReferenceQueue and a Finalizer thread polls the queue. 在我读过的许多文章中-他们说对象可能被推送到ReferenceQueue,而终结器线程轮询队列。 So is there a way, I can check the queue myself? 有没有办法自己检查队列? (I know a memory dump will show this, but sometimes the file is too huge to transfer from a live system to a local machine and perform diagnostics). (我知道内存转储会显示此信息,但是有时文件太大,无法从实时系统传输到本地计算机并执行诊断)。

  2. What exactly is the difference between a trivial and non-trivial finalize() method? 平凡的finalize()方法与非平凡的finalize()方法到底有什么区别? Couldn't find an article which explains this. 找不到解释此问题的文章。

  3. If finalize() method is not a good idea, why does AbstractPlainSocketImpl,FileInputStream and others implement it? 如果finalize()方法不是一个好主意,为什么AbstractPlainSocketImpl,FileInputStream和其他实现它? And how is that, their finalize method helps them in GC and not to be part of unreachable or dead code? 而且,它们的finalize方法如何在GC中帮助他们,而不是成为无法访问的代码或无效代码的一部分?

  4. While using jvisualvm or jmc - the committed heap size is shown as 600MB. 使用jvisualvm或jmc时-提交的堆大小显示为600MB。 But when I execute the below command on our Linux environment it shows me the memory as 800MB+. 但是,当我在Linux环境上执行以下命令时,它显示的内存为800MB +。

     ps --cols 500 -C java -o user,ppid,pid,pcpu,rss,size,vsize,cmd | grep <uid> | awk '{ print $3,$4,$5/1024}' 

Environment Details 环境细节

    Number of cores: 2
    OS: Red Hat Enterprise Linux Server release 6.5
    Total Physical Memory: 7.69GB
    JVM: Java HotSpot(TM) 64-Bit Server VM (24.45-b08) for linux-amd64 JRE (1.7.0_45-b18)
    JVM Command Line Arguments: -Xloggc:../logs/Job-gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintHeapAtGC -XX:-PrintTenuringDistribution -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=5M -XX:-CITime -XX:-PrintClassHistogram -XX:-PrintConcurrentLocks -XX:-PrintAdaptiveSizePolicy -XX:-TraceClassLoading -XX:-TraceClassUnloading -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=7091 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=server.com

    Garbage Collector used (this info is from JMC): ParallelScavenge for Young and ParallelOld for Old.

I know a memory dump will show this, but sometimes the file is too huge to transfer from a live system to a local machine and perform diagnostics 我知道内存转储会显示此信息,但有时文件太大,无法从实时系统传输到本地计算机并执行诊断

Command tar -czf dump.tar.gz dump.hprof may help you to transfer that big file. 命令tar -czf dump.tar.gz dump.hprof可以帮助您传输该大文件。

3GB -> 100MB. 3GB-> 100MB。

The compress rate of dump file would be so great. 转储文件的压缩率将是如此之高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM