JedisPool
package redis; import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig; public class JedisPoolUtil {
private static volatile JedisPool jedisPool = null;
private JedisPoolUtil() {}
public static JedisPool getJedisPoolIntence() {
if(null == jedisPool) {
synchronized (JedisPoolUtil.class) {
if(null == jedisPool) {
JedisPoolConfig poolConfig = new JedisPoolConfig();
poolConfig.setMaxActive(1000);
poolConfig.setMaxIdle(32);
poolConfig.setMaxWait(100*1000);
poolConfig.setTestOnBorrow(true); jedisPool = new JedisPool(poolConfig, "192.168.88.128", 6379);
return jedisPool;
}
}
}
return jedisPool;
} public static void relace(JedisPool jedisPool, Jedis jedis) {
if(null != jedis) {
jedisPool.returnResourceObject(jedis);
}
}
}
package redis; import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool; public class TestPool {
public static void main(String[] args) {
JedisPool jedisPool = JedisPoolUtil.getJedisPoolIntence();
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
jedis.set("aa", "bb");
System.out.println("success");
} catch (Exception e) {
e.printStackTrace();
}finally {
JedisPoolUtil.relace(jedisPool, jedis);
}
}
}
双锁单例
JedisPool的更多相关文章
- Redis JedisPool
获取连接池,通常连接池为单例,这里使用 双端检测机制保证只有一个实例 public class JedisPoolUtil { private static volatile JedisPool je ...
- JedisPool异常Jedis链接处理
问题现象(jedis-2.1.0.jar) 基于JedisPool管理Jedis对象,通过get方法获取值,出现key对应的value值错误,例如: K V a a b b Jedis.get(“a” ...
- spring boot redis缓存JedisPool使用
spring boot redis缓存JedisPool使用 添加依赖pom.xml中添加如下依赖 <!-- Spring Boot Redis --> <dependency> ...
- jedisPool.returnBrokenResource 弃用
for (int i = 0; i < 1000000 ; i++) { //使用Pool的方式 调用Redis JedisPool jedisPool = SpringContextHolde ...
- redis之如何配置jedisPool参数
JedisPool的配置参数很大程度上依赖于实际应用需求.软硬件能力,JedisPool的配置参数大部分是由JedisPoolConfig的对应项来赋值的. maxActive:控制一个poo ...
- [redis] redis 存取键值对常用的三种使用方式 - Jedis、JedisPool、Jedis分布式
|-Jedis 普通方式 |-JedisPool 连接池方式(需要引入pool相关jar) |-Jedis 分布式 (需要引入pool相关jar) 引入jedis2.7.0和commons.pool2 ...
- JedisPool连接池实现难点
[http://jiangwenfeng762.iteye.com/blog/1280700] [可改进的问题] 问题是jedispool有没有办法监控状态,比如说当前连接有多少,当前idle连接 ...
- JedisPool使用原理和源代码
1,JedisPool的使用 <!-- 连接池的配置信息 --><beanid="jedisConfig"class="redis.clients.je ...
- JedisPool操作
Jedis 使用 commons-pool 完成池化实现. 先做个配置文件(properties文件): #最大分配的对象数 redis.pool.maxActive=1024 #最大能够保持idel ...
- redis 工具类 单个redis、JedisPool 及多个redis、shardedJedisPool与spring的集成配置
http://www.cnblogs.com/edisonfeng/p/3571870.html http://javacrazyer.iteye.com/blog/1840161 http://ww ...
随机推荐
- 为什么有时候在Windbg中下断点下不了呢??
1.今天我发现我下断点的地方是我声明的变量,变量还仅仅是声明,没有赋值.因此不能下断点. 2.当不能下断点时,如何解决呢? (1)重启Vmware虚拟机.(2)在虚拟机中恢复“快照”.
- C# 用代码返回上一页
若我们在后台.cs文件中想做到让浏览器返回上一页,我们可以在.cs代码中这样写 Page.ClientScript.RegisterStartupScript(Page.GetType(), &quo ...
- c# 导入c++ dll
1.类的函数的内联实现 #include "stdafx.h" #include "testdll.h" #include <iostream> # ...
- Row_Number() OVER()函数使用举例
语法:ROW_NUMBER() OVER(PARTITION BY COLUMN ORDER BY COLUMN) 简单的说row_number()从1开始,为每一条分组记录返回一个数字,这里的ROW ...
- javascript总结2: Date对象
1 Date 对象 Date 对象用于处理日期与时间. Date()的方法很多,这里只总结工作必备的方法! 2 常用方法 创建个 Date 对象:const mydate=new Date(); &l ...
- DateType--字符类型
--=====================================================字符集 ASCII (American Standard Code for Informa ...
- "ServiceStack.Redis.RedisNativeClient”的方法“get_Db”没有实现。
解决办法: 1.首先通过nuget程序包管理器将相关依赖项卸载干净 2.检查各项目模块中的package.config里还有没有redis的节点,如果已经存在就删除掉 3.去别的正常的项目中看一下re ...
- angular Docheck
import { Component, OnInit, Input, OnChanges, SimpleChanges, DoCheck } from '@angular/core'; @Compon ...
- 以太坊系列之十一: 零起步使用remix开发智能合约
一步一步使用remix开发智能合约 最新版的remix(2017-8-3)只能使用在线开发了,已经没有离线版本了,并且好像在线版本要FQ才能访问(自行解决). 1.打开remix 注意地址如果是htt ...
- html5 video使用autoplay属性时,声音混乱
html5 video使用autoplay属性时,声音混乱 页面代码 Index.html <html xmlns="http://www.w3.org/1999/xhtml" ...