Hibernate异步处理常用方法总结 - // 异步执行的方法
Hibernate异步处理的常用方法有:
@Async@AsyncExecutorService
@Service
public class MyService {
@Autowired
private MyRepository myRepository;
@Async
public void asyncMethod() {
// 异步执行的方法
}
}
@Transactional@TransactionalTransactionManager
@Service
public class MyService {
@Autowired
private MyRepository myRepository;
@Transactional
public void syncMethod() {
// 同步执行的方法
}
}
@Scheduled@ScheduledScheduledExecutorService
@Service
public class MyService {
@Autowired
private MyRepository myRepository;
@Scheduled(fixedRate = 5000) // 每5秒执行一次
public void asyncMethod() {
// 异步执行的方法
}
}
@EnableAsync@EnableAsync
@Configuration
@EnableAsync
public class AppConfig {
// ...其他配置...
}
@Async@Async@Component@Service
@Service
public class MyService {
@Autowired
private MyRepository myRepository;
@Async 拼多多帮助力入口
public void syncMethod() {
// 同步执行的方法
}
},Hibernate异步处理常用方法总结