Bouncy Castle内存溢出
现象:
堆内存溢出,java.lang.OutOfMemoryError: Java heap space
用jmap查看,显示
num #instances #bytes class name
----------------------------------------------
1: 6736096 269443840 java.util.LinkedHashMap$Entry
2: 1360211 116788016 [C
3: 3560635 113940320 java.util.Hashtable$Entry
4: 1648844 92335264 java.security.Provider$Service
5: 3181146 76347504 java.security.Provider$ServiceKey
6: 21269 54483872 [Ljava.util.HashMap$Entry;
7: 1456006 46592192 java.lang.String
8: 5837 26712568 [Ljava.util.Hashtable$Entry;
9: 722313 23248472 [Ljava.lang.Object;
10: 142687 20602688
11: 142687 19416024
12: 718388 17241312 java.util.ArrayList
13: 13487 14511200
14: 13487 10430624
15: 11194 8157360
16: 127989 7303936
17: 29127 3953880 [B
18: 19410 3739704 [I
19: 35613 3133944 java.lang.reflect.Method
20: 69481 2223392 java.util.HashMap$Entry
21: 2886 2137144
22: 14176 1474304 java.lang.Class
23: 18304 1127368 [S
24: 21231 1068624 [[I
25: 12681 811584 com.ibatis.sqlmap.engine.mapping.parameter.ParameterMapping
26: 12681 811584 com.ibatis.sqlmap.engine.mapping.parameter.ParameterMapping
27: 11454 641424 java.util.LinkedHashMap
28: 9802 627328 com.ibatis.sqlmap.engine.mapping.sql.dynamic.elements.SqlTag
29: 9802 627328 com.ibatis.sqlmap.engine.mapping.sql.dynamic.elements.SqlTag
30: 20443 490632 com.ibatis.sqlmap.engine.mapping.sql.SqlText
31: 20443 490632 com.ibatis.sqlmap.engine.mapping.sql.SqlText
32: 9738 467424 java.util.HashMap
33: 9231 443088 org.apache.catalina.loader.ResourceEntry
34: 10718 428720 java.lang.ref.SoftReference
35: 21067 416344 [Lcom.ibatis.sqlmap.engine.mapping.parameter.ParameterMapping;
36: 21067 416344 [Lcom.ibatis.sqlmap.engine.mapping.parameter.ParameterMapping;
37: 12940 414080 java.lang.ref.WeakReference
38: 19937 413624 [Ljava.lang.Class;
39: 660 385440
40: 10423 376192 [Ljava.lang.String;
----------------------------------------------
1: 6736096 269443840 java.util.LinkedHashMap$Entry
2: 1360211 116788016 [C
3: 3560635 113940320 java.util.Hashtable$Entry
4: 1648844 92335264 java.security.Provider$Service
5: 3181146 76347504 java.security.Provider$ServiceKey
6: 21269 54483872 [Ljava.util.HashMap$Entry;
7: 1456006 46592192 java.lang.String
8: 5837 26712568 [Ljava.util.Hashtable$Entry;
9: 722313 23248472 [Ljava.lang.Object;
10: 142687 20602688
11: 142687 19416024
12: 718388 17241312 java.util.ArrayList
13: 13487 14511200
14: 13487 10430624
15: 11194 8157360
16: 127989 7303936
17: 29127 3953880 [B
18: 19410 3739704 [I
19: 35613 3133944 java.lang.reflect.Method
20: 69481 2223392 java.util.HashMap$Entry
21: 2886 2137144
22: 14176 1474304 java.lang.Class
23: 18304 1127368 [S
24: 21231 1068624 [[I
25: 12681 811584 com.ibatis.sqlmap.engine.mapping.parameter.ParameterMapping
26: 12681 811584 com.ibatis.sqlmap.engine.mapping.parameter.ParameterMapping
27: 11454 641424 java.util.LinkedHashMap
28: 9802 627328 com.ibatis.sqlmap.engine.mapping.sql.dynamic.elements.SqlTag
29: 9802 627328 com.ibatis.sqlmap.engine.mapping.sql.dynamic.elements.SqlTag
30: 20443 490632 com.ibatis.sqlmap.engine.mapping.sql.SqlText
31: 20443 490632 com.ibatis.sqlmap.engine.mapping.sql.SqlText
32: 9738 467424 java.util.HashMap
33: 9231 443088 org.apache.catalina.loader.ResourceEntry
34: 10718 428720 java.lang.ref.SoftReference
35: 21067 416344 [Lcom.ibatis.sqlmap.engine.mapping.parameter.ParameterMapping;
36: 21067 416344 [Lcom.ibatis.sqlmap.engine.mapping.parameter.ParameterMapping;
37: 12940 414080 java.lang.ref.WeakReference
38: 19937 413624 [Ljava.lang.Class;
39: 660 385440
40: 10423 376192 [Ljava.lang.String;
解决方案:
/usr/local/java/jdk1.6.0_37/jre/lib/security/java.security 加上一行 security.provider.9=org.bouncycastle.jce.provider.BouncyCastleProvider
修改RSAUtil new org.bouncycastle.jce.provider.BouncyCastleProvider() -> "BC"
修改RSAUtil new org.bouncycastle.jce.provider.BouncyCastleProvider() -> "BC"
static{
if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null){
logger.info("security provider BC not found");
Security.addProvider(new BouncyCastleProvider());
}
}
部署:从WAR中移出bouncycastle的jar,移到/usr/local/java/jdk1.6.0_37/jre/lib/ext下面(不需要加静态导入),移到tomcat/lib下面(需要加静态导入)
if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null){
logger.info("security provider BC not found");
Security.addProvider(new BouncyCastleProvider());
}
}
部署:从WAR中移出bouncycastle的jar,移到/usr/local/java/jdk1.6.0_37/jre/lib/ext下面(不需要加静态导入),移到tomcat/lib下面(需要加静态导入)