From d50d378c339c5ea6cfe9159fb81514927f041d01 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 23 Dec 2013 18:46:15 +0000 Subject: [PATCH] Prevent more than one app at a time from running --- .../boot/cli/command/RunCommand.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/RunCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/RunCommand.java index 587a3b5595..3dab61b0c8 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/RunCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/RunCommand.java @@ -53,7 +53,7 @@ public class RunCommand extends OptionParsingCommand { public void stop() { if (this.getHandler() != null) { - ((RunOptionHandler) this.getHandler()).runner.stop(); + ((RunOptionHandler) this.getHandler()).stop(); } } @@ -78,8 +78,21 @@ public class RunCommand extends OptionParsingCommand { this.quietOption = option(asList("quiet", "q"), "Quiet logging"); } + public synchronized void stop() { + if (this.runner != null) { + this.runner.stop(); + } + this.runner = null; + } + @Override - protected void run(OptionSet options) throws Exception { + protected synchronized void run(OptionSet options) throws Exception { + + if (this.runner != null) { + throw new RuntimeException( + "Already running. Please stop the current application before running another."); + } + FileOptions fileOptions = new FileOptions(options); if (options.has(this.editOption)) {