@Async使用笔记

  1. 必须是public方法
  2. 必须是非static方法
  3. 方法调用的实例必须由spring创建和管理

代码示例如下:

// 创建Foo类
@Component
class Foo { @Async public static void bar(){ /* ... */ } @Async public void bar2(){ /* ... */ } }

 

// 调用示例代码
class
Test { @Autowired
//
@Lazy(true)可以解决spring循环引用的问题
 Foo foo;
 test(){
     Foo.bar(); // Not async
     foo.bar(); // Not async
     foo.bar2(); // Async
  }
}

 

相关文章:

  • 2022-12-23
  • 2021-12-17
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
相关资源
相似解决方案