From 61b5a04df0ec5d5dbc74525825a9214ad67074dd Mon Sep 17 00:00:00 2001 From: Krzysztof Styrc Date: Wed, 17 Jun 2015 14:30:19 +0200 Subject: [PATCH] Shutdown ExecutorService on stop() --- src/main/java/redis/embedded/AbstractRedisInstance.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/redis/embedded/AbstractRedisInstance.java b/src/main/java/redis/embedded/AbstractRedisInstance.java index f8d2fbf8..abeae789 100644 --- a/src/main/java/redis/embedded/AbstractRedisInstance.java +++ b/src/main/java/redis/embedded/AbstractRedisInstance.java @@ -17,7 +17,7 @@ abstract class AbstractRedisInstance implements Redis { private Process redisProcess; private final int port; - private final ExecutorService executor = Executors.newSingleThreadExecutor(); + private ExecutorService executor; protected AbstractRedisInstance(int port) { this.port = port; @@ -47,6 +47,7 @@ private void logErrors() { final InputStream errorStream = redisProcess.getErrorStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(errorStream)); Runnable printReaderTask = new PrintReaderRunnable(reader); + executor = Executors.newSingleThreadExecutor(); executor.submit(printReaderTask); } @@ -78,6 +79,9 @@ private ProcessBuilder createRedisProcessBuilder() { @Override public synchronized void stop() throws EmbeddedRedisException { if (active) { + if (executor != null && !executor.isShutdown()) { + executor.shutdown(); + } redisProcess.destroy(); tryWaitFor(); active = false;