不当引起内存泄露"/>
BouncyCastleProvider使用不当引起内存泄露
项目中用到的代码如下:
Cipher cipher = Cipher.getInstance("RSA", new BouncyCastleProvider());
项目长时间运行,就会出现JceSecurity占用的内存越来越多,而且不会释放。
具体分析请看这篇
有如下修复的方法:
方法一、
private static BouncyCastleProvider bouncyCastleProvider = null;public static synchronized BouncyCastleProvider getInstance() {if (bouncyCastleProvider == null) {bouncyCastleProvider = new BouncyCastleProvider();}return bouncyCastleProvider;}......KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA", getInstance());
方法二、
Provider provider=Security.getProvider(BouncyCastleProvider.PROVIDER_NAME);if(provider==null){provider=new BouncyCastleProvider();Security.addProvider(provider);}Cipher cipher = Cipher.getInstance("RSA","BC");
使用BouncyCastleProvider加密的时候千万别乱new BouncyCastleProvider()
切记!!!
切记!!!
切记!!!
更多推荐
BouncyCastleProvider使用不当引起内存泄露
发布评论