I understand that you want to run this application when the server starts. The best way would be to implement ServletContextListenerand run the application in a method contextInitialized(). For instance.
public class Config implements ServletContextListener {
private YourApp yourApp;
public void contextInitialized(ServletContextEvent event) {
yourApp = new YourApp();
yourApp.start();
}
public void contextDestroyed(ServletContextEvent event) {
yourApp.shutdown();
}
}
web.xml :
<listener>
<listener-class>com.example.Config</listener-class>
</listener>
. HttpServlet, HTTP- .
, , . , Runnable ExecutorService.