I have written a small spring-boot application without embedded servers. It is intended to run from command line and stay running until the VM gets signalled. What is the intended way of in the spring-boot framework (v2.0) to keep the application alive as a service? Should I have a Thread.currentThread().wait();
as last statement in my run(ApplicationArguments args)
method? Is there an enabling annotation?
In a Spring-Boot application without web server, what is the correct way to keep it running?
Asked Answered
from org.springframework.boot.web.embedded.netty.NettyWebServer
, Official.
private void startDaemonAwaitThread(DisposableServer disposableServer) {
Thread awaitThread = new Thread("server") {
@Override
public void run() {
disposableServer.onDispose().block();
}
};
awaitThread.setContextClassLoader(getClass().getClassLoader());
awaitThread.setDaemon(false);
awaitThread.start();
}
that kind of contradicts the question condition of having a Spring-Boot application without a webserver, doesn't it? –
Plainsong
I just assume there is another server instead of default web server, so it is necessary to keep application running. Refer to the official implementation, you can start a thread which blocked and waiting your server close. –
Orlon
© 2022 - 2024 — McMap. All rights reserved.
System.in.read
would block until the first key stroke... I want the thing just wait for Crtl-C. – Plainsong