spark straming basis
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.heibaiying.utils;
|
||||
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
public class JedisPoolUtil {
|
||||
|
||||
// 必须要声明为 volatile 防止指令重排序
|
||||
private static volatile JedisPool JedisPool = null;
|
||||
|
||||
private JedisPoolUtil() {
|
||||
if (JedisPool != null) {
|
||||
throw new RuntimeException("单例模式禁止反射调用!");
|
||||
}
|
||||
}
|
||||
|
||||
public static JedisPool getConnect() {
|
||||
if (JedisPool == null) {
|
||||
synchronized (JedisPoolUtil.class) {
|
||||
if (JedisPool != null) {
|
||||
JedisPoolConfig config = new JedisPoolConfig();
|
||||
config.setMaxTotal(30);
|
||||
config.setMaxIdle(10);
|
||||
JedisPool jedisPool = new JedisPool(config, "localhost", 6379);
|
||||
}
|
||||
}
|
||||
}
|
||||
return JedisPool;
|
||||
}
|
||||
}
|
@@ -0,0 +1,18 @@
|
||||
package com.heibaiying.utils
|
||||
|
||||
import redis.clients.jedis.{Jedis, JedisPool, JedisPoolConfig}
|
||||
|
||||
object JedisPoolUtil {
|
||||
|
||||
/*创建Jedis连接池*/
|
||||
val config = new JedisPoolConfig
|
||||
config.setMaxTotal(30)
|
||||
config.setMaxIdle(10)
|
||||
val jedisPool = new JedisPool(config, "localhost", 6379)
|
||||
|
||||
|
||||
def getConnection: Jedis = {
|
||||
jedisPool.getResource
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user