Redis+linux的Bundle池化(四)
来源:互联网 发布:经济学书籍推荐 知乎 编辑:程序博客网 时间:2024/06/06 02:02
使用Bundle的池化的好处,是它底层帮我们封装了读取,
redis.properties文件的方法,我们直接调用就可以。
跟前面的案列一样,导入包,然后利用Bundle。
注意:
读取文件时不要加后缀名了。
最后有个池的释放,以后加了spring框架就不需要了。
代码:
import java.util.ResourceBundle;import redis.clients.jedis.Jedis;import redis.clients.jedis.JedisPool;import redis.clients.jedis.JedisPoolConfig;public class Test1 { private static JedisPool pool; static { ResourceBundle bundle = ResourceBundle.getBundle("redis"); if (bundle == null) { throw new IllegalArgumentException("[redis.properties] is not found!"); } JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(Integer.valueOf(bundle.getString("redis.pool.maxActive"))); config.setMaxIdle(Integer.valueOf(bundle.getString("redis.pool.maxIdle"))); config.setMaxWaitMillis(Long.valueOf(bundle.getString("redis.pool.maxWait"))); config.setTestOnBorrow(Boolean.valueOf(bundle.getString("redis.pool.testOnBorrow"))); config.setTestOnReturn(Boolean.valueOf(bundle.getString("redis.pool.testOnReturn"))); pool = new JedisPool(config, bundle.getString("redis.ip"), Integer.valueOf(bundle.getString("redis.port"))); } public static void main(String[] args) { // Jedis jedis=new Jedis("192.168.15.215"); Jedis jedis = pool.getResource(); String keys = "name"; jedis.del(keys); jedis.set(keys, "yjl"); String value = jedis.get(keys); System.out.println(value); pool.returnBrokenResource(jedis);//回收池连接 }}
0 0
- Redis+linux的Bundle池化(四)
- Redis (四 redis的虚拟内存管理)
- Redis (四 redis的虚拟内存管理)
- Redis(四)Redis的数据结构
- (四)Redis的数据类型
- OSGi介绍(四)第一个bundle
- OpenCV实现SfM(四):Bundle Adjustment
- redis学习系列(四)--redis基础SDS的构造
- Redis常用的命令(四)-------hash
- 四.Redis的数据结构
- 浅尝Unity 3D的Asset Bundle知识(四)-----基础打牢篇
- Linux系列之redis环境搭建(四)
- redis命令(四)
- redis命令(四)
- Redis学习(四)
- Redis的安装(linux)
- Redis之四的字典
- Redis系列(四)Redis性能实战
- Swift TextField
- ajax解决中文数据乱码问题
- 连续子数组的最大和
- 四则运算
- spring-hibernate-Junit4测试心得
- Redis+linux的Bundle池化(四)
- POJ-1691 Painting A Board
- c++实验2作业
- Go语言切片的用法和本质
- Oracle 11g必须开启的服务及服务详细介绍
- 初识Xamarin——mac os x下环境的搭建
- linux的pam验证
- 最短路-弗洛伊德(Floyd)算法
- HDOJ 2064 汉诺塔III