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的更多相关文章

  1. Redis JedisPool

    获取连接池,通常连接池为单例,这里使用 双端检测机制保证只有一个实例 public class JedisPoolUtil { private static volatile JedisPool je ...

  2. JedisPool异常Jedis链接处理

    问题现象(jedis-2.1.0.jar) 基于JedisPool管理Jedis对象,通过get方法获取值,出现key对应的value值错误,例如: K V a a b b Jedis.get(“a” ...

  3. spring boot redis缓存JedisPool使用

    spring boot redis缓存JedisPool使用 添加依赖pom.xml中添加如下依赖 <!-- Spring Boot Redis --> <dependency> ...

  4. jedisPool.returnBrokenResource 弃用

    for (int i = 0; i < 1000000 ; i++) { //使用Pool的方式 调用Redis JedisPool jedisPool = SpringContextHolde ...

  5. redis之如何配置jedisPool参数

      JedisPool的配置参数很大程度上依赖于实际应用需求.软硬件能力,JedisPool的配置参数大部分是由JedisPoolConfig的对应项来赋值的.   maxActive:控制一个poo ...

  6. [redis] redis 存取键值对常用的三种使用方式 - Jedis、JedisPool、Jedis分布式

    |-Jedis 普通方式 |-JedisPool 连接池方式(需要引入pool相关jar) |-Jedis 分布式 (需要引入pool相关jar) 引入jedis2.7.0和commons.pool2 ...

  7. JedisPool连接池实现难点

    [http://jiangwenfeng762.iteye.com/blog/1280700]   [可改进的问题] 问题是jedispool有没有办法监控状态,比如说当前连接有多少,当前idle连接 ...

  8. JedisPool使用原理和源代码

    1,JedisPool的使用 <!-- 连接池的配置信息 --><beanid="jedisConfig"class="redis.clients.je ...

  9. JedisPool操作

    Jedis 使用 commons-pool 完成池化实现. 先做个配置文件(properties文件): #最大分配的对象数 redis.pool.maxActive=1024 #最大能够保持idel ...

  10. redis 工具类 单个redis、JedisPool 及多个redis、shardedJedisPool与spring的集成配置

    http://www.cnblogs.com/edisonfeng/p/3571870.html http://javacrazyer.iteye.com/blog/1840161 http://ww ...

随机推荐

  1. PC端QT源码编译

    转载:http://blog.sina.com.cn/s/blog_c2b97b1d01016x1i.html 1.下载源码(前面已经提到了) 选择合适自己的源码. 先用"uname -a& ...

  2. jq获取table总行数

    var rows = $('table').find("tr").length;

  3. Django rest_framework----认证,权限,频率组件

    认证 from rest_framework.authentication import BaseAuthentication from rest_framework.exceptions impor ...

  4. XE下 SVG格式的图标使用方法

    下载一个SVG格式的图标,千图网,http://tool.58pic.com/tubiaobao/ 用txt文本打开SVG图标 拖一个PathLabel控件 在PathLabel控件的Data属性添加 ...

  5. 表单使用clone方法后, 原有select无法生效

    textarea和select的值clone的时候会丢掉,在clone的时候将val再重新赋值一下,如果知道这个了就加单了   测试发现,textarea和select的jquery的clone方法有 ...

  6. angular 服务之间依赖注入

    import { Injectable } from '@angular/core'; @Injectable() export class LoggerServiceService { constr ...

  7. 分享我访问google的方法

    对于程序员来说,有很多技术问题还是通过互联网搜索来解决的.所以百度.google对于我们是多少的重要.但是GOOGLE现在无法访问了.怎么办呢.以下是我访问google的方法. 首先自己制作了一个简单 ...

  8. centos7下git的安装和配置

    git的安装: yum 源仓库里的 Git 版本更新不及时,最新版本的 Git 是 1.8.3.1,但是官方最新版本已经到了 2.9.2.想要安装最新版本的的 Git,只能下载源码进行安装. 1. 查 ...

  9. IEnumerable、GetEnumerator、IEnumerator之间的关系。

    了解了这些也就明白了遍历的原理,晚安. using System; using System.Collections; public class Person { public Person(stri ...

  10. sqlite数据库文件查看