Closed itswuanran closed 4 years ago
CreateNoteCommand createNoteCommand = new CreateNoteCommand(noteId, title); AsyncTaskResult<CommandResult> asyncTaskResult = commandService.executeAsync(createNoteCommand, CommandReturnType.EventHandled).join(); Assert.notNull(asyncTaskResult, "asyncTaskResult"); commandService.executeAsync(createNoteCommand, CommandReturnType.EventHandled).join(); commandService.executeAsync(createNoteCommand, CommandReturnType.EventHandled).join(); commandService.executeAsync(createNoteCommand, CommandReturnType.EventHandled).join(); commandService.executeAsync(createNoteCommand, CommandReturnType.EventHandled).join(); ChangeNoteTitleCommand titleCommand = new ChangeNoteTitleCommand(noteId, title + " change"); // always block here Task.get(commandService.executeAsync(titleCommand, CommandReturnType.EventHandled));
这个执行语句会一直阻塞,获取不到future的结果
聚合根需要有构造参数,reset mailbox 需要改为同步执行
阻塞的原因是因为使用了Future.get()等待一个不能完成的任务,在使用Socket发送命令结果时可能会出现异常导致一直阻塞 优化思路: 将CommandResultProcessor的commandTaskDict优化成一个固定时间过期的Map,默认5s
这个执行语句会一直阻塞,获取不到future的结果