java web spring异步方法

 

在项目中,时常会有异步调用的需求

 

web.xml配置


    spring mvc servlet
    springMvc
    class>org.springframework.web.servlet.DispatcherServletclass>
    
      spring mvc 配置文件
      contextConfigLocation
      classpath:spring-mvc.xml
    
    1
    <async-supported>trueasync-supported>
  
  
    springMvc
    /
  

添加:true

 

spring  xml添加配置:

    
    "myExecutor" pool-size="10"  />
    "myExecutor"/>

 

然后demo:

@Service
@EnableAsync
public class DevicesEditLogService {

    @Async
    public void recordEditLog(Map param) {
        
    }

}

类上添加@EnableAsync, 方法上添加@Async, 

添加@Service, 其他类可以注入这个实例,并调用成员方法

 

注:有了解到,如果@Async修饰的方法和调用此方法的其他方法在同一个类中,不会生效

具体参照:https://blog.csdn.net/ClementAD/article/details/47339519

你可能感兴趣的:(java web spring异步方法)