1

I tried to create a socket thread inside Spring Boot. This is the initial start up class in Spring Framework.

@Component
public class InitialStartUp implements ApplicationListener<ContextRefreshedEvent> {

    private Logger logger = LoggerFactory.getLogger(getClass());


    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {

        // Start the Socket server
        try {
            ListenerSocket listenerSocket = new ListenerSocket();
            listenerSocket.run();
            logger.info("Starting listener socket server"); // <-- Never called
        } catch (Exception e) {
            logger.info(e.getMessage());
        }

    } 
}

But the problem is that the logger.info method above will never be called. Why? Spring Boot run the listenerSocket thread, but never "goes out" from it. Why?

Is there some way I can do to make the logger.info be called?

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
euraad
  • 2,467
  • 5
  • 30
  • 51

0 Answers0