关于生产redisclient连接无法释放和redission连接无法释放的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于BSRedisDesktopClientv1.0.4发布,Redi
关于生产redis client 连接无法释放和redission连接无法释放的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于BS Redis Desktop Client v1.0.4 发布,Redis 桌面客户端、c3p0 连接无法释放、Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password、httpclient4.5.4使用默认方式创建连接资源无法释放的问题等相关知识的信息别忘了在本站进行查找喔。
本文目录一览:- 生产redis client 连接无法释放(redission连接无法释放)
- BS Redis Desktop Client v1.0.4 发布,Redis 桌面客户端
- c3p0 连接无法释放
- Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password
- httpclient4.5.4使用默认方式创建连接资源无法释放的问题
生产redis client 连接无法释放(redission连接无法释放)
原因是spring配置文件,开启了事务导致的,redis是缓存用的,不需要开启事务,正确的配置如下:
<!--redis操作模版,使用该对象可以操作redis -->
<bean id="redisTemplateTax">
<property name="connectionFactory" ref="connectionFactoryTax" />
<!--如果不配置Serializer,那么存储的时候缺省使用String,如果用User类型存储,那么会提示错误User can''t cast to String!! -->
<property name="keySerializer" >
<bean/>
</property>
<property name="valueSerializer" >
<bean/>
</property>
<property name="hashKeySerializer">
<bean/>
</property>
<property name="hashValueSerializer">
<bean/>
</property>
<!--开启事务 -->
<property name="enableTransactionSupport" value="false"></property>
</bean >
BS Redis Desktop Client v1.0.4 发布,Redis 桌面客户端
BS Redis Desktop Client v1.0.4 已经发布,Redis 桌面客户端。
此版本更新内容包括:
- 把keys * 替换使用scan,
- hash使用hscan,
- 新增zset数据支持,使用zscan,
- 新增按钮添加zset数据类型
- list类型使用异步,
- set类型使用异步和sscan 软件下载地址
详情查看:https://gitee.com/fuyoo/bs/releases/v1.0.4
c3p0 连接无法释放
最近有个小项目,struts2 + jdbc,用了c3p0的连接池,发现每当使用的连接数总和超过最大连接数就死了,即获取不到connection,如果c3p0设置了checkoutTimeout,则会抛出An attempt by a client to checkout a Connection has timed out.异常,在网上找了一下午资料,大致是使用过的连接没有被释放掉,该怎么解决呢
连接池代码如下:
import java.beans.PropertyVetoException; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.SQLException; import java.util.Properties; import com.mchange.v2.c3p0.ComboPooledDataSource; public class ConnectionPool { private static class SingletonHolder { static ConnectionPool instance = new ConnectionPool(); } static final String configFile = "c3p0.properties"; private static ComboPooledDataSource ds; private static int i =1; /** * 得到一个连接池实例 * * @return */ public static ConnectionPool getInstance() { return SingletonHolder.instance; } /** * 初始化连接池配置 */ private ConnectionPool() { try { Properties p = new Properties(); InputStream is = ConnectionPool.class.getClassLoader() .getResourceAsStream(configFile); p.load(is); ds = new ComboPooledDataSource(); try { ds.setDriverClass((String) p.get("database.driverClassName")); } catch (PropertyVetoException e) { e.printStackTrace(); } ds.setJdbcUrl((String) p.get("jdbc.url")); ds.setUser((String) p.get("jdbc.username")); ds.setPassword((String) p.get("jdbc.password")); ds.setInitialPoolSize(Integer.parseInt((String) p .get("initialPoolSize"))); ds.setMaxPoolSize(Integer.parseInt((String) p.get("maxPoolSize"))); ds.setMinPoolSize(Integer.parseInt((String) p.get("minPoolSize"))); ds.setAcquireIncrement(Integer.parseInt((String) p.get("acquireIncrement"))); ds.setAutoCommitOnClose(Boolean.parseBoolean((p .get("autoCommitOnClose").toString()))); ds.setMaxIdleTime(Integer.parseInt(p.getProperty("maxIdleTime"))); ds.setAcquireRetryDelay(Integer.parseInt((String) p.get("acquireRetryDelay"))); ds.setBreakAfterAcquireFailure(Boolean.parseBoolean((p .get("breakAfterAcquireFailure").toString()))); ds.setCheckoutTimeout(Integer.parseInt((String) p.get("checkoutTimeout"))); ds.setIdleConnectionTestPeriod(Integer.parseInt((String) p.get("idleConnectionTestPeriod"))); ds.setNumHelperThreads(Integer.parseInt((String) p.get("numHelperThreads"))); ds.setPropertyCycle(Integer.parseInt((String) p.get("propertyCycle"))); ds.setMaxStatements(Integer.parseInt((String) p.get("maxStatements"))); ds.setDebugUnreturnedConnectionStackTraces(true); } catch (IOException e) { e.printStackTrace(); } } /** * 获得一个连接 * * @return * @throws SQLException */ public Connection getConnection() { try { System.out.println(i++); return ds.getConnection(); } catch (SQLException e) { e.printStackTrace(); } return null; } }
c3p0具体配置文件如下:
#################### 数据库连接设置 ########################### database.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://127.0.0.1:3309/db jdbc.username=root jdbc.password=root ##################### C3p0 连接池配置 ##################### # 始化时创建的连接数,应在minPoolSize与maxPoolSize之间取值。默认为3 initialPoolSize=20 # 接池中保留的最大连接数。默认为15 maxPoolSize=30 minPoolSize=20 # 当连接池中的连接用完时,C3P0一次性创建新连接的数目 默认 3 acquireIncrement=10 # 定义在从数据库获取新连接失败后重复尝试获取的次数,默认为30 acquireRetryAttempts=100 # 两次连接中间隔时间,单位毫秒,默认为1000 acquireRetryDelay=1000 # 连接关闭时默认将所有未提交的操作回滚。默认为false autoCommitOnClose=false # 获取连接失败将会引起所有等待获取连接的线程抛出异常。但是数据源仍有效保留,并在下 # 次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试获取连接 # 失败后该数据源将申明已断开并永久关闭。默认为false breakAfterAcquireFailure=false # 当连接池用完时客户端调用getConnection()后等待获取新连接的时间,超时后将抛出 # SQLException,如设为0则无限期等待。单位毫秒,默认为0 checkoutTimeout=20000 # 最大空闲时间,超过空闲时间的连接将被丢弃。为0或负数则永不丢弃。默认为0 maxIdleTime=60 # 每60秒检查所有连接池中的空闲连接。Default: 0 idleConnectionTestPeriod=60 # C3P0是异步操作的,缓慢的JDBC操作通过帮助进程完成。扩展这些操作可以有效的提升性能 #通过多线程实现多个操作同时被执行。默认为3 numHelperThreads=3 # 用户修改系统配置参数执行前最多等待的秒数。默认为300 propertyCycle=300 maxStatements=0
Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password
在对redis 做测试的时候遇到以上问题,经过排查问题出现在,redis的启动方式。
- 第一种是使用服务端命令 ./redis-server
这种方式启动 默认无密码 ,如果在写java redis 是传参数 就会造成异常 Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password is set
2、第二种指定配置文件 执行命令 :[grid@h1 src]$ ./redis-server ../redis.conf
redis通过属性requirepass 设置访问密码,但没有设置该属性时,客户端向服务端发送AUTH请求就会出现最上面的异常 ,所以解决办法就是 指定配置文件进行启动。
httpclient4.5.4使用默认方式创建连接资源无法释放的问题
hi,
求教一个问题,本人最近刚把httpclient版本升级到4.5.4,项目中有个需要用到http post请求发送文件的地方,发现参照这个官方链接https://hc.apache.org/httpcomponents-client-4.5.x/httpclient/examples/org/apache/http/examples/client/ClientConnectionRelease.java 的代码,写了一个工具类,感觉该释放的资源都释放了,但是项目在生产运行了一段时间之后,看内存dump,有大量的
PoolingHttpClientConnectionManager
对象没有被回收。代码如下:
package com.best.oasis.ocr.util;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class HttpUtil {
private static Logger logger = LoggerFactory.getLogger(HttpUtil.class);
/**
* Http post请求
*/
public static String doHttpPost(String postUrl, Map<String, String> headers,
Map<String, String> params, String filePath) {
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
HttpPost post = getHttpPost(postUrl, headers, params, filePath);
CloseableHttpResponse response = httpClient.execute(post);
try {
InputStream inputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
try {
inputStream = response.getEntity().getContent();
inputStreamReader = new InputStreamReader(inputStream);
bufferedReader = new BufferedReader(inputStreamReader);
return bufferedReader.readLine();
}catch (Exception e) {
logger.warn("do http post fail: ", e);
}finally {
if (bufferedReader != null) {
logger.info("release bufferedReader: " + filePath);
bufferedReader.close();
}
if (inputStreamReader != null) {
logger.info("release inputStreamReader: " + filePath);
inputStreamReader.close();
}
if (inputStream != null) {
logger.info("release inputStream: " + filePath);
inputStream.close();
}
}
}
} catch (Exception e) {
logger.warn("do http post fail: ", e);
} finally {
if (response != null) {
logger.info("release response: " + filePath);
response.close();
}
if (post != null) {
logger.info("release HttpPost: " + filePath);
post.releaseConnection();
}
}
} catch (Exception e) {
logger.warn("do http post fail: ", e);
} finally {
if (httpClient != null) {
logger.info("release httpClient: " + filePath);
httpClient.close();
logger.info("release connectionManager: " + filePath);
httpClient.getConnectionManager().shutdown();
}
}
} catch (Exception e) {
logger.warn("do http post fail: ", e);
}
return "";
}
private static HttpPost getHttpPost(String postUrl, Map<String, String> headers,
Map<String, String> params, String filePath) {
HttpPost post = new HttpPost(postUrl);
String[] headerKeys = headers.keySet().toArray(new String[headers.keySet().size()]);
for (String key : headerKeys) {
post.setHeader(key, headers.get(key));
}
FileBody fileBody = new FileBody(new File(filePath));
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
multipartEntityBuilder.addPart("express_image", fileBody);
String[] paramKeys = params.keySet().toArray(new String[params.keySet().size()]);
for (String key : paramKeys) {
StringBody valueBody = new StringBody(params.get(key), ContentType.TEXT_PLAIN);
multipartEntityBuilder.addPart(key, valueBody);
}
post.setEntity(multipartEntityBuilder.build());
return post;
}
}
ClosableHttpClient和其对应的连接管理器都已经显式释放了,但是项目跑大概一个多月之后,内存中有大量的InternalHttpClient和PoolingHttpClientConnectionManager对象,导致OOM.
请大神帮忙解答下,谢谢了。
关于生产redis client 连接无法释放和redission连接无法释放的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于BS Redis Desktop Client v1.0.4 发布,Redis 桌面客户端、c3p0 连接无法释放、Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password、httpclient4.5.4使用默认方式创建连接资源无法释放的问题等相关内容,可以在本站寻找。
本文标签: