Spring MVC how to get progress of running async task

后端 未结 4 861
轻奢々
轻奢々 2020-12-30 10:09

I would like to start an asynchronous task from within controller like in following code sniplet from Spring docs.

import org.springframework.core.task.Tas         


        
4条回答
  •  伪装坚强ぢ
    2020-12-30 11:11

    Ignoring synchronization issues you could do something like this:

      private class MessagePrinterTask implements Runnable { 
        private int cn; 
    
        public int getCN() {
          return cn;
        }
    
        ...
      }
    
    
      public class TaskExecutorExample { 
        MessagePrinterTask printerTask;
    
        public void printMessages() { 
          printerTask = new MessagePrinterTask();
          taskExecutor.execute(printerTask); 
        }
        ...
      }
    

提交回复
热议问题