This is regarding spring-boot-maven-plugin.
I create this issue because I notice an odd behaviour when I try to run mvn verify. Currently using the latest 2.7.2 spring-boot-maven-plugin plugin, when I run mvn verify on a project, the maven job run successfully, but the process is hang. I can see that the process using port 9001 never dies and the only way for me to run mvn verify successfully again, is to manually kill the process.
I am experiencing this problem on an application I recently starting working on and I've managed to reproduce it in a sample app but still not on the clear why it happens, probably due to my limited of understanding of threads in the jvm. In order to reproduce you need to defined a different TaskScheduler. So we have one bean like this:
@Bean
public TaskScheduler taskScheduler() {
return new ConcurrentTaskScheduler();
}
And you need a Scheduled task similar to this:
@Scheduled(fixedRate = 1800000)
public void runScheduledTask() {
System.out.println("Running scheduledTask");
}
Then the plugin looks like this. Observe that if I were to run it with fork=false everything works perfectly but this is not an option in out case:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.7.2</version>
<configuration>
<jvmArguments>
-Dspring.application.admin.enabled=true
</jvmArguments>
</configuration>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
Then we just run mvn verify and the process on port 9001 never dies.
For a fully working example I created a repo, please see: https://github.com/PatrikKoskenniemi/SampleSchedulingProblem
We could just remove the ConcurrentTaskScheduler bean and make it work but it feels like I'm missing something here, maybe someone else knows why this occurs?
Comment From: wilkinsona
Thanks for the sample. The stop goal closes the application context to allow the JVM to exit. Your use of ConcurrentTaskScheduler means that non-daemon threads are left running after the context has been closed. These threads then prevent the JVM from exiting. Please see https://github.com/spring-projects/spring-boot/issues/29301 where someone else had a similar problem for some suggestions on how things should be done instead.