spark straming basis

This commit is contained in:
罗祥
2019-05-27 13:43:37 +08:00
parent 5ccbdbf89e
commit 79228ff9ef
7 changed files with 177 additions and 0 deletions

View File

@@ -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;
}
}

View File

@@ -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
}
}