ソースを参照

添加 isStarted 保障只能启动一次

James 3 年 前
コミット
00c292fa08
1 ファイル変更10 行追加0 行削除
  1. 10 0
      src/main/java/com/jfinal/plugin/redis/RedisPlugin.java

+ 10 - 0
src/main/java/com/jfinal/plugin/redis/RedisPlugin.java

@@ -33,6 +33,8 @@ import com.jfinal.plugin.redis.serializer.ISerializer;
  */
 public class RedisPlugin implements IPlugin {
 	
+	protected volatile boolean isStarted = false;
+	
 	protected String cacheName;
 	
 	protected String host;
@@ -94,6 +96,10 @@ public class RedisPlugin implements IPlugin {
 	}
 	
 	public boolean start() {
+		if (isStarted) {
+			return true;
+		}
+		
 		JedisPool jedisPool;
 		if      (port != null && timeout != null && database != null && clientName != null)
 			jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password, database, clientName);
@@ -115,6 +121,8 @@ public class RedisPlugin implements IPlugin {
 		
 		Cache cache = new Cache(cacheName, jedisPool, serializer, keyNamingPolicy);
 		Redis.addCache(cache);
+		
+		isStarted = true;
 		return true;
 	}
 	
@@ -123,6 +131,8 @@ public class RedisPlugin implements IPlugin {
 		if (cache == Redis.mainCache)
 			Redis.mainCache = null;
 		cache.jedisPool.destroy();
+		
+		isStarted = false;
 		return true;
 	}