How to prevent Spring Boot daemon/server application from closing/shutting down immediately?

I found the solution, using org.springframework.boot.CommandLineRunner + Thread.currentThread().join(), e.g.: (note: code below is in Groovy, not Java) package id.ac.itb.lumen.social import org.slf4j.LoggerFactory import org.springframework.boot.CommandLineRunner import org.springframework.boot.SpringApplication import org.springframework.boot.autoconfigure.SpringBootApplication @SpringBootApplication class LumenSocialApplication implements CommandLineRunner { private static final log = LoggerFactory.getLogger(LumenSocialApplication.class) static void main(String[] args) { SpringApplication.run LumenSocialApplication, args } @Override void run(String… args) throws Exception { … Read more

How does the JVM terminate daemon threads? or How to write daemon threads that terminate gracefully

I just wrote the following code as a test: public class DaemonThreadPlay { public static void main(String [] args) { Thread daemonThread = new Thread() { public void run() { while (true) { try { System.out.println(“Try block executed”); Thread.sleep(1000l); } catch (Throwable t) { t.printStackTrace(); } } } @Override public void finalize() { System.out.println(“Finalize method … Read more