我正在使用restful web服务。在我有一个方法,通过使用这种方法我发送通知和邮件。我的方法工作正常,唯一的问题是在调用此方法后获得成功响应之前2,3秒会弹出通知。
@Override
@Transactional
public MedikmResponse createNPostCcbrQuestion(CreateNPostCcbrQuestionRequest createNPostCcbrQuestionRequest, HttpServletRequest request) {
logger.info("#########################Post Ccbr Question#############################");
MedikmResponse medikmResponse=new MedikmResponse();
try {
String token = request.getHeader("authToken");
User user = userDao.findUserByAuthToken(token);
if (user != null) {
/**
* Question Creation
*/
CcbrQuestion ccbrQuestion=new CcbrQuestion();
ccbrQuestion.setQuestiomtext(createNPostCcbrQuestionRequest.getCcbrQuestionText());
Integer questionId=ccbrQuestionDao.saveCcbrQuestion(ccbrQuestion);
ccbrQuestion.setQuestionId(questionId);
/* ***
* Question post
*/
TbDiscussionForumQuestion tbDiscussionForumQuestion=new TbDiscussionForumQuestion();
tbDiscussionForumQuestion.setCCBRQuestionId(ccbrQuestion);
tbDiscussionForumQuestion.setTBDiscussionId(new TbDiscussionForum(createNPostCcbrQuestionRequest.getTbdiscussionId()));
tbDiscussionForumQuestion.setPhysicianId(new Physician(user.getPhysicianId().getPhysicianId()));
tbDiscussionForumQuestion.setQuestion(createNPostCcbrQuestionRequest.getCcbrQuestionText());
tbDiscussionForumQuestion.setQuestionDate(new Date());
//tbDiscussionForumQuestionDao.saveTbDiscussionForumQuestion(tbDiscussionForumQuestion);
TbDiscussionForum discussionForum=tbDiscussionForumDao.findTbDiscussionForumbyTbId(createNPostCcbrQuestionRequest.getTbdiscussionId());
discussionForum.getTbDiscussionForumQuestionCollection().add(tbDiscussionForumQuestion);
tbDiscussionForumDao.updateTbDiscussionForum(discussionForum);
String[] deviceIdList=getParticpentDeviceIdList(discussionForum.getCaseId().getCaseId(), user);
medikmResponse.setAuthenticationKey(user.getAuthToken());
notificationSender.sendPostedCcbrQuestionToVMDCParticipant(discussionForum.getCaseId(), user.getPhysicianId(), createNPostCcbrQuestionRequest.getCcbrQuestionText());//sending mail
if(deviceIdList.length!=0){
notificationService.sendNotificationToIOS(deviceIdList,discussionForum.getCaseId().getCaseId(),createNPostCcbrQuestionRequest.getTbdiscussionId(),"Question");
}
medikmResponse.setResponseCode(MedikmConstants.SUCCESS_CODE);
medikmResponse.setResponseMessage(MedikmConstants.SUCCESS_MESSAGE);
}else{
medikmResponse.setResponseCode(MedikmConstants.FAILURE_CODE);
medikmResponse.setResponseMessage(MedikmConstants.USER_DOES_NOT_EXIST);
logger.info("############ USER_DOES_NOT_EXIST #############"+ MedikmConstants.USER_DOES_NOT_EXIST);
}
return medikmResponse;
}catch(Exception ex){
ex.printStackTrace();
return null;
}
}
答案 0 :(得分:0)
为此我在sendNotificationToIOS方法中添加@Async注释,并且在添加此注释后需要在xml中添加