From e561cc1997889b03c1260e7755727051e06bedb5 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 12 May 2016 16:53:07 +0100 Subject: [PATCH] Don't use a separate thread in the launcher to call app's main method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using a separate thread to call the application's main method is unnecessary – the context class loader of the current thread can be updated instead – and makes exception and exit code handling more complicated than it needs to be. This commit updates the Launcher so that it calls the main method runner using the current (main) thread. As a result, any exception that's thrown will be caught by the JVM and result in a non-zero exit code being returned from the process. Closes gh-5922 --- .../main/java/org/springframework/boot/loader/Launcher.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java index 3bcd43ac94..f79a939ec3 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/Launcher.java @@ -100,10 +100,8 @@ public abstract class Launcher { protected void launch(String[] args, String mainClass, ClassLoader classLoader) throws Exception { Runnable runner = createMainMethodRunner(mainClass, args, classLoader); - Thread runnerThread = new Thread(runner); - runnerThread.setContextClassLoader(classLoader); - runnerThread.setName(Thread.currentThread().getName()); - runnerThread.start(); + Thread.currentThread().setContextClassLoader(classLoader); + runner.run(); } /**