package com.gurkensalat.chronos;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ApplicationContextEvent;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextStoppedEvent;
import org.springframework.stereotype.Component;

@Component
public class LayerListRunner implements CommandLineRunner, ApplicationListener<ApplicationContextEvent>
{
    private final static Logger LOGGER = LoggerFactory.getLogger(LayerListRunner.class);

    private static boolean running = true;

    public void run(String... args) throws Exception
    {
        LOGGER.info("Running my additional runner");

        while (running)
        {
            LOGGER.info("Doing some work...");

            Thread.sleep(15 * 1000);
        }

        LOGGER.info("Finished my additional runner");
    }

    public void onApplicationEvent(ApplicationContextEvent event)
    {
        LOGGER.info("Context received event {}", event);
        if (event instanceof ContextStoppedEvent || event instanceof ContextClosedEvent)
        {
            // No clue why onApplicationEvent(ContextStoppedEvent) is not called, fake it here...
            running = false;
            LOGGER.info("Set running to {}", running);
        }
    }
}

@@ -744,24 +744,70 @@
 er.class);%0A%0A
+    private static Thread thisThread = null;%0A%0A
     private 
@@ -838,16 +838,17 @@
  true;%0A%0A
+%0A
     publ
@@ -948,24 +948,69 @@
  runner%22);%0A%0A
+        thisThread = Thread.currentThread();%0A
         whil
@@ -1075,24 +1075,58 @@
 work...%22);%0A%0A
+            try%0A            %7B%0A    
             
@@ -1150,16 +1150,211 @@
  1000);%0A
+            %7D%0A            catch (InterruptedException ie)%0A            %7B%0A                // We don't want to continue looping if death was requested%0A                running = false;%0A            %7D%0A
         
@@ -1764,32 +1764,32 @@
 unning = false;%0A
-
             LOGG
@@ -1827,16 +1827,52 @@
 nning);%0A
+            thisThread.interrupt();%0A
         

Improve lifecycle