zoukankan      html  css  js  c++  java
  • jedisPoolUtil 单例

       JedisPoolUtil

    public class JedisPoolUtil {
        private static volatile JedisPool jedisPool = null;// 被volatile修饰的变量不会被本地线程缓存,对该变量的读写都是直接操作共享内存。
        private JedisPoolUtil() {
        }
        public static JedisPool getJedisPoolInstance() {
            if (null == jedisPool) {
                synchronized (JedisPoolUtil.class) {
                    if (null == jedisPool) {
                        JedisPoolConfig poolConfig = new JedisPoolConfig();
                        poolConfig.setMaxTotal(1000);
                        poolConfig.setMaxIdle(32);
                        poolConfig.setMaxWaitMillis(100 * 1000);
                        poolConfig.setTestOnBorrow(true);
                        jedisPool = new JedisPool(poolConfig, "192.168.120.129", 6379);
                    }
                }
            }
            return jedisPool;
        }
        public static void release(JedisPool jedisPool, Jedis jedis) {
            if (null != jedis) {
                Jedis jedis2 = null;
                try {
                    jedis2 = jedisPool.getResource();
                } finally {
                    jedis2.close();
                }
            }
        }
    }

    使用

    public class TestJedisPool {
        public static void main(String[] args) {
            JedisPool jedisPool = JedisPoolUtil.getJedisPoolInstance();
            Jedis jedis = null;
            try {
                jedis = jedisPool.getResource();
                jedis.set("k18", "v183");
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                JedisPoolUtil.release(jedisPool, jedis);
            }
        }
    }
  • 相关阅读:
    摩托罗拉SE4500 德州仪器TI Omap37xx/AM3715/DM3730/AM3530 wince6.0/Windows Mobile 6.5平台 二维软解调试记录及相关解释
    摩托罗拉SE4500 三星 S3C6410 Wince6.0平台软解码调试记录以及驱动相关问题解释
    MSM8909+Android5.1.1之系统烧录
    PIC16F914SEG脚中电路图注意事项
    PIC16F914ADC模块采集数据转换
    PIC914AD模块使用记录
    PIC914 LCDCON液晶控制寄存器用法
    PIC914SEG设置方法
    示波器用法
    检测单片机是否启动
  • 原文地址:https://www.cnblogs.com/sdgtxuyong/p/14708650.html
Copyright © 2011-2022 走看看