Trouble stopping a tomcat server that is running a web application with a while (true) loop

后端 未结 2 1112
孤街浪徒
孤街浪徒 2021-01-24 03:47

I\'m developing a web application to be deployed onto Tomcat. When Tomcat is started, I use a servlet (in web.xml) to call a Java class:


    <         


        
2条回答
  •  余生分开走
    2021-01-24 04:48

    You have to place the code with the loop in a different thread and start the thread from your consumer.

    private void consume() {
      Thread x = new Thread(new Runnable() {
        @Override
        public void run() {
          while(true) {
          ....
          }
       });
       x.start();
    }
    

提交回复
热议问题