0

I am writing a Springboot application embedding Tomcat as a Web Server.

At startup, some of my threads are ready (and so start doing their job) before Tomcat is. For many contraints I have, I want that these threads do nothing before Tomcat is ready

But I don't know how to decided to block/unblock my threads; to do so, I need to be informed of the Tomcat status. Is there:

  • a way to ask: isWebServerStarted()?
  • or a way to be notified asynchronously by a message saying: WEB_SERVER_IS_STARTED?

Thank you for help

FYI, I don't want to declare a kind of "private ReST endpoint" that my application could try to reach in order to guess whether the webserver is ready

Philippe MESMEUR
  • 737
  • 8
  • 22
  • 1
    Looks like it's the same question: https://stackoverflow.com/questions/28240403/spring-boot-wait-for-web-server-to-start – Bor Laze Jul 28 '19 at 20:07

1 Answers1

0

Go with a ServletContextListener. Annotate your class with @WebListener and tell spring configuration about this listener by adding @ServletComponentScan annotation.

fiveelements
  • 3,649
  • 1
  • 17
  • 16