Keed Thread Alive Spring Application

Keed Thread Alive Spring Application

Spring standalone java application thread don’t alive infinitely and by default it runs only one time as your java program. For example if you are running web application where you start it only once and it keeps alive until you stop the server. This is important for Spring standalone application of any java application if you want start your program only once keep them alive infinitely until you stop then please use below program. As you could use this logic any java application but here I am particularly talking about spring application so I will create small Spring application to show you how it works:

  • Create maven project name: KeepThreadAlive below is folder structure:

Keed Thread Alive Spring Application

  • pom.xml:

  • spring-context.xml:

  • log4j2.xml:

  • KeepThreadAliveSpringApp.java: Main class to load the spring application context and keep thread alive infinitely until you stop the application:

  • To test right click KeepThreadAliveSpringApp.java –> Run As –> Java Application. Below is example output:

Keed Thread Alive Spring Application

  • For more information please read spring documentation here

Leave a Reply

Your email address will not be published. Required fields are marked *