Fixed loop doesn;'t exist on server shutdown

This commit is contained in:
ham1255 2020-06-05 13:28:26 +04:00
parent eb73047d14
commit 5b438eb148
1 changed files with 4 additions and 1 deletions

View File

@ -16,6 +16,7 @@ public class RedisSub extends JedisPubSub implements Runnable{
private AddonPlugin plugin; private AddonPlugin plugin;
private Jedis j; private Jedis j;
private String[] channels; private String[] channels;
private Boolean isShuttingDown = false;
public RedisSub(AddonPlugin plugin, Jedis j, List<String> channels) { public RedisSub(AddonPlugin plugin, Jedis j, List<String> channels) {
this.plugin = plugin; this.plugin = plugin;
@ -37,7 +38,7 @@ public class RedisSub extends JedisPubSub implements Runnable{
private void newJedis() { private void newJedis() {
//this.unsubscribe(); //this.unsubscribe();
this.j.close(); this.j.close();
while (true){ while (!isShuttingDown){
try { try {
plugin.getLogger().info("reconnecting to Redis!"); plugin.getLogger().info("reconnecting to Redis!");
this.j = plugin.getJedisPool().getResource(); this.j = plugin.getJedisPool().getResource();
@ -48,6 +49,7 @@ public class RedisSub extends JedisPubSub implements Runnable{
try { Thread.sleep(4000);}catch (InterruptedException ignored){} try { Thread.sleep(4000);}catch (InterruptedException ignored){}
} }
} }
if (isShuttingDown) return;
plugin.getJedisExecutionService().execute(this); plugin.getJedisExecutionService().execute(this);
} }
@ -67,6 +69,7 @@ public class RedisSub extends JedisPubSub implements Runnable{
} }
public void shutdown(){ public void shutdown(){
isShuttingDown = true;
this.unsubscribe(); this.unsubscribe();
j.close(); j.close();
} }