- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们有一个 java 应用程序,我可以说它也使用了相当多的字符串变量。此外,我们启动时将最大和初始内存设置为 256Mb。此后运行了一段时间,直到最近我们发现首先是一次GC,近两周后又是一次GC。由此我们发现FC的平均值为0.2145s,YGC的平均值为0.0511s。我们不确定这些值是否合适或会导致其他结果?我们决定将内存增加到 512Mb,并研究一些其他 GC 设置,例如 CMS 设置?还应该优化代码,例如字符串变量的使用吗?通常什么对象或变量类型会移动到旧对象中?
Timestamp S0 S1 E O P YGC YGCT FGC FGCT GCT
2752472.6 69.74 0.00 3.67 51.72 44.17 4614 235.630 2 0.429 236.059
2752477.6 69.74 0.00 5.38 51.72 44.17 4614 235.630 2 0.429 236.059
2752482.6 69.74 0.00 7.51 51.72 44.17 4614 235.630 2 0.429 236.059
2752487.6 69.74 0.00 9.52 51.72 44.17 4614 235.630 2 0.429 236.059
2752492.6 69.74 0.00 10.55 51.72 44.17 4614 235.630 2 0.429 236.059
代码片段
BoneCP connectionPool = null;
class ConnectionHandler implements Runnable {
private Socket receivedSocketConn1;
ConnectionHandler(Socket receivedSocketConn1) {
this.receivedSocketConn1=receivedSocketConn1;
}
Connection dbconn = null;
public void run() { // etc
BufferedWriter writeBuffer = null;
BufferedReader readBuffer = null;
String capturedMessage="";
try{
dbconn = connectionPool.getConnection();
dbconn.setAutoCommit(false);
while ((nextChar=readBuffer.read()) != -1){
capturedMessage += (char) nextChar;
if (nextChar == '*')
{
try{
//all queries here.
//for insert query this how i do
Statement stmt1 = null;
stmt1 = dbconn.createStatement();
String insertQuery3 =........
count = stmt9.executeUpdate(insertQuery3);
try{
if ( stmt1!= null ){ stmt1.close();
}
else{
System.out.println("No stm1 exist");
}
}catch(SQLException ex){
System.out.println("SQLException has been caught for stmt1");
ex.printStackTrace(System.out);
}
///For select we do this
Statement stmt2 = null;
stmt2 = dbconn.createStatement();
String selectQuery2= .........
ResultSet rs2 = stmt2.executeQuery(selectQuery2);
if(rs2.next())
{
}
try{
if ( rs2!= null ){
rs2.close();
} else{
System.out.println("No rs2 exist");
}
if ( stmt2!= null ){
stmt2.close();
} else{
System.out.println("No stm2 exist");
}
}catch(SQLException ex)
{
System.out.println("SQLException has been caught for stmt2");
ex.printStackTrace(System.out);
}
dbconn.commit
}
catch (SQLException ex){
ex.printStackTrace(System.out);
try{
dbconn.rollback();
}
catch (Exception rollback){
rollback.printStackTrace(System.out);
}
}
catch (Exception e){
e.printStackTrace(System.out);
try{
dbconn.rollback();
}
catch (Exception rollback){
rollback.printStackTrace(System.out);
}
}
finally
{
}
}
catch (SocketTimeoutException ex){
ex.printStackTrace();
}
catch (IOException ex){
ex.printStackTrace();
}
catch (Exception ex){
ex.printStackTrace(System.out);
}
finally{
try{
if ( dbconn != null ){
dbconn.close();
}
else{
System.out.println("dbConn is null in finally close");
}
}
catch(SQLException ex){
ex.printStackTrace();
}
try{
if ( writeBuffer != null ){
writeBuffer.close();
}
else{
System.out.println("w is null in finally close");
}
}
catch(IOException ex){
ex.printStackTrace(System.out);
}
}
}
}
终结器分析来自sun.misc.Launcher$ExtClassLoader @ 0xe003a648 (50%)大小:11.2 MB 类:196 个对象:201.7k 类加载器:7
共有91个对象实现了finalize方法。
Histogram of Objects with Finalize Method
Class Name Objects Shallow Heap
com.mysql.jdbc.JDBC4Connection
First 10 of 38 objects 38 42,560
java.net.SocksSocketImpl
First 10 of 39 objects 39 4,368
java.util.jar.JarFile
All 6 objects 6 384
java.util.zip.Inflater
All 6 objects 6 192
java.util.concurrent.ScheduledThreadPoolExecutor
All 1 objects 1 80
java.util.concurrent.ThreadPoolExecutor
All 1 objects 1 72
Total: 6 entries
91 47,656
终结器分析
(46%)大小:13.6 MB 类:578 个对象:304.8k 类加载器:4
共有 19,341 个对象实现了 Finalize 方法。
Class Name Objects Shallow Heap
java.net.SocksSocketImpl
First 10 of 18,354 objects 18,354 2,055,648
com.sun.mail.smtp.SMTPTransport
First 10 of 162 objects 162 25,920
java.io.FileOutputStream
First 10 of 742 objects 742 23,744
com.mysql.jdbc.JDBC4Connection
First 10 of 15 objects 15 16,800
java.util.jar.JarFile
First 10 of 20 objects 20 1,280
java.util.zip.Inflater
First 10 of 25 objects 25 800
java.util.concurrent.ThreadPoolExecutor
All 8 objects 8 576
sun.net.www.protocol.jar.URLJarFile
All 5 objects 5 400
java.util.concurrent.ScheduledThreadPoolExecutor
All 2 objects 2 160
java.lang.ClassLoader$NativeLibrary
All 4 objects 4 128
java.io.FileInputStream
All 3 objects 3 96
sun.jdbc.odbc.JdbcOdbcDriver
All 1 objects 1 24
Total: 12 entries
19,341 2,125,576
来自 org.rzo.yajsw.boot.WrapperClassLoader @ 0xe02818c0 的终结器分析 (4%)大小:966.3 KB 类:361 个对象:19.9k 类加载器:3
共有22个对象实现了finalize方法。
Histogram of Objects with Finalize Method
Class Name Objects Shallow Heap
java.util.jar.JarFile
First 10 of 11 objects 11 704
java.util.zip.Inflater
All 10 objects 10 320
java.util.concurrent.ThreadPoolExecutor
All 1 objects 1 72
Total: 3 entries
22 1,096
历史实时结果。
num #instances #bytes class name
----------------------------------------------
1: 6001 18078232 [I
2: 44562 7196072 [B
3: 103183 6054240 [C
4: 31832 4786936 <constMethodKlass>
5: 31832 4340240 <methodKlass>
6: 31638 3543456 java.net.SocksSocketImpl
7: 20127 3542352 com.mysql.jdbc.JDBC4ResultSet
8: 41022 3461576 [Ljava.util.HashMap$Entry;
9: 104185 3333920 java.lang.String
10: 20198 3070096 com.mysql.jdbc.StatementImpl
11: 20323 2926512 com.mysql.jdbc.Field
12: 60329 2895792 java.util.TreeMap
13: 2343 2800032 <constantPoolKlass>
14: 61239 2449560 java.util.TreeMap$Entry
15: 149690 2395040 java.lang.Object
16: 41000 1968000 java.util.HashMap
17: 2343 1895080 <instanceKlassKlass>
18: 1954 1569536 <constantPoolCacheKlass>
19: 31623 1517904 java.net.SocketInputStream
套接字的初始启动
71: 2 224 java.net.SocksSocketImpl
176: 1 32 java.net.Socket
202: 1 24 java.net.InetSocketAddress
206: 1 24 java.net.ServerSocket
运行 50 个套接字后。
19: 52 5824 java.net.SocksSocketImpl
37: 50 2400 java.net.SocketInputStream
48: 51 1632 java.net.Socket
88: 8 384 java.net.SocketOutputStream
95: 8 320 java.net.SocketTimeoutException
135: 7 112 java.net.Socket$3
136: 7 112 java.net.Socket$2
229: 1 24 java.net.ServerSocket
最佳答案
512 MB 听起来并不算多,而且可能不值得您花时间进一步优化它。 BTW 512 Mb 是 512 兆位。
中长期存在的对象最终会进入老年代。
您可以使用内存分析器优化代码,以减少字符串的使用。您可以使用 StringBuilder 回收对象并减少 GC 压力,这是导致对象错误地最终进入永久空间的常见原因。
极端地说,您可能会发现可以消除所有字符串生成,但我怀疑它是否值得,并且将内存增加到 1 GB 可能会更简单/更便宜。
关于java - GC和YGC的发生以及下一步的行动当然,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19500611/
在我们对延迟敏感的应用程序中,我们有缓存数据(驻留在 TG 中)和在 YG 中消亡的短暂对象。我已经看到次要 GC 时间和主要 GC 时间有显着差异。我怀疑这与TG的尺寸相对较大有关。谁能解释 GC
我看到了多个建议运行 GC.Collect(GC.MaxGeneration) 的答案。 既然方法GC.Collect()会收集所有存在的分代,那么两者有什么区别吗? 也许如果只有两代而不是三代,GC
我们正在使用 UseParallelGC。 GC 日志看起来像 2016-06-09T19:38:17.362+0000:655312.397:[完整GC(人体工程学)[PSYoungGen:2291
我最近看到了两个非常好的和有教育意义的语言讲座: This first one由 Herb Sutter 撰写,介绍了 C++0x 的所有漂亮和酷炫的特性,为什么 C++ 的 future 似乎比以往
我们正在运行 gerrit 2.10.7,我们偶尔会遇到损坏的对象没有被 gerrit gc 修复的问题,即使 git gc 可以很好地修复它们。 另一方面,我读到 gerrit gc 会创建优化其他
我试图避免 Full GC(来自下面的 gc.log 示例)在生产中的 Tomcat 中运行 Grails 应用程序。关于如何更好地配置 GC 有什么建议吗? 14359.317:[完整 GC 143
我试图通过在析构函数中使用 console.WriteLine() 来确保释放某个类的实例,但输出从未出现。 我仔细搜索了任何挥之不去的引用资料以及事件订阅,但没有找到。只是为了我自己的理智,在我继续
之前看过一篇文章,说FGC影响时序,导致application出错结果。 代码示例如下: long start = System.currentTimeInMillis(); doSomething(
在 Java 中,我们可以使用 System.gc() 方法来建议 GC。今天我从this link开始了解C#中的GC.Collect()方法。 . 但我对解释有些不清楚。 第一行。 Forces
我理解 Python GC 有两种工作方式: 1) 基本引用计数 - 当“name”设置为“Tom”时,“John”下方的引用计数为零 name = "John" name = "Tom" (Refe
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
今天我们使用并发标记清除,具体如下: -XX:+UseConcMarkSweepGC 我看到一些文章推荐使用这种形式的附加参数: -XX:+UseConcMarkSweepGC -XX:+CMSInc
当我运行我的程序时,logcat 显示很多 GC Activity 喜欢 GC freed 10324 objects/ 510376 bytes in 103 ms GC freed 10324 o
2013-11-26T10:19:30.011+0800: [GC [ParNew: 2432484K->19997K(2696640K), 0.0378270 secs] 5560240K->315
在执行 GC 时,JVM 会遍历 Activity 对象,并清除未标记的对象。 根据: How to Tune Java Garbage Collection “Full GC的执行时间相对Minor
我有一个分布式缓存应用程序(内存绑定(bind),由于与集群中其他节点的交互而具有网络 I/O)在 JVM 1.7.0_51 中运行,带有 G1 垃圾收集器。这是 JVM 配置: -server -X
首先,我想让您知道,这是一个理论问题而不是实际问题,我只是好奇弱引用对象是如何被释放的。让我们快速记住 Java 中的弱引用是什么。粗略地说WeakReference意味着当没有指向“我”的强引用时,
这是运行大约 10 分钟后的输出。 Heap PSYoungGen total 7040K, used 0K [0x24060000, 0x247c0000, 0x26790000)
我正在运行一个应用程序,在 Weblogic 上使用 java 5 和 CMS 垃圾收集器。在垃圾收集日志中,我看到了消息日志,其中大部分消息我可以使用 Sun 的 Java HotSpot 虚拟机中
我有一个 ConcurrentMap> map = new ConcurrentHashMap>(); 并且希望当 SoftReference 的引用被 GC 时从映射中删除键/值对。 我该如何实现这
我是一名优秀的程序员,十分优秀!