spark straming basis

This commit is contained in:
罗祥
2019-05-27 13:43:49 +08:00
parent 79228ff9ef
commit 5407561d44
7 changed files with 66 additions and 73 deletions

View File

@@ -1,30 +1,30 @@
package com.heibaiying.utils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class JedisPoolUtil {
// 必须要声明为 volatile 防止指令重排序
private static volatile JedisPool JedisPool = null;
/* 声明为volatile防止指令重排序 */
private static volatile JedisPool jedisPool = null;
private JedisPoolUtil() {
if (JedisPool != null) {
throw new RuntimeException("单例模式禁止反射调用!");
}
}
private static final String HOST = "localhost";
private static final int PORT = 6379;
public static JedisPool getConnect() {
if (JedisPool == null) {
/* 双重检查锁实现懒汉式单例 */
public static Jedis getConnection() {
if (jedisPool == null) {
synchronized (JedisPoolUtil.class) {
if (JedisPool != null) {
if (jedisPool == null) {
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(30);
config.setMaxIdle(10);
JedisPool jedisPool = new JedisPool(config, "localhost", 6379);
jedisPool = new JedisPool(config, HOST, PORT);
}
}
}
return JedisPool;
return jedisPool.getResource();
}
}

View File

@@ -1,18 +0,0 @@
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
}
}