Skip to content

Commit

Permalink
Shutdown ExecutorService on stop()
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Styrc authored and Krzysztof Styrc committed Jun 17, 2015
1 parent 9bf3979 commit 61b5a04
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/redis/embedded/AbstractRedisInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 61b5a04

Please sign in to comment.