Ich habe eine Frage über Spring @ Async Annotation. Ich habe einen Controller einen Dienst (GnInsuranceDetailsService) autowiredSpring @ Async Annotation
@RequestMapping(value="/agn/AP0W01A_010/insertDetail.do")
public ResponseEntity<?> insertDetail(@ModelAttribute("dto")GnInsuranceDetailsDTO dto,HttpSession session) throws Exception {
gnInsuranceDetailsDTO.setBkFlag(getAgnUserInfo(session).getBkFlag());
gnInsuranceDetailsService.insertGnInsuranceDetail(dto);//open another thread to insert data
MessageDTO dto = new MessageDTO(AgnConstant.INSERT_SUCCESS);
return new ResponseEntity<MessageDTO>(dto,HttpStatus.OK);// increase return time for client
}
und die Service insertGnInsuranceDetail Methode, die ich @Async up-Methode deklarieren.
@Transactional(readOnly = false)
@Async
public void insertGnInsuranceDetail(GnInsuranceDetailsDTO gnInsuranceDetailsDTO) throws Exception{
GnInsuranceDetails entity = gnInsuranceDetailsDTO.convert();
gnInsuranceDetailsDAO.save(detailsEntity);
}
habe ich die @Async für die Service-Methode Controller Antwortzeit für Client-Seite zu erhöhen, aber es funktioniert nicht, wie ich glaube. Verliere ich etwas? Oder Wie kann ich am einfachsten ändern?
Hellow, @ kuhajeyan.I den Test-Code Gewinde verwenden. schlaf (10000L) vor insertGnInsuranceDetail Methode begin.but nicht funktioniert.Controller wird warten> 10s für Service-EinsatzGnInsuranceDetail-Methode abgeschlossen. –
@HamiltonLin sind Sie sicher, dass Sie @ EnableAsync in der Konfiguration für @ Async zu arbeiten – kuhajeyan
So konfigurieren Sie diese Konfiguration im Frühjahr –