Spring Boot Task Manager no return value of the asynchronous task calls

A, service layer

 

 

com.uos.schedule.service Package; 

Import org.springframework.scheduling.annotation.Async; 
Import org.springframework.stereotype.Service; 

/ ** 
 * Service Layer 
 * / 
@Service 
public class OwnAsynService { 
    @Async 
    public void the sendSMS () InterruptedException {throws 
        System.out.println ( "SMS authentication service method calls"); 
        Long the startTime = System.currentTimeMillis (); 
        the Thread.sleep (5000); 
        Long endTime = System.currentTimeMillis (); 

        System.out.println ( " SMS service execution completion time consuming: \ T "+ (endTime-the startTime)); 
    } 
}

OwnAsynService

Two, controller layer

 

 

package com.uos.schedule.controller;

import com.uos.schedule.service.OwnAsynService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *控制层
 */
@RestController
public class OwnAsyncController {
    @Autowired
    private OwnAsynService ownAsynService;

    @GetMapping(value = {"sendSMS"})
    public String sendSMS() throws InterruptedException {
        Long startTime = System.currentTimeMillis();
        ownAsynService.sendSMS();
        Long endTime = System.currentTimeMillis();
        System.out.println("主业务执行消耗完成时间:\t" + (endTime - startTime));
        return "success";
    }
}

OwnAsyncController

三、主程序类

 

 四、结果测试

 

 

Guess you like

Origin www.cnblogs.com/my-program-life/p/12047396.html