@Async和executor之间的区别
我找不到使用执行人而不是@ASYNC春季注释的任何理由。 有人可以向我解释@ASYNC和执行者之间有什么区别?
I can't find any reason for using executor instead of @Async Spring annotation.
Can someone explain me what is the difference between @Async and executors?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行者使用更复杂,但在运行函数的方式上提供了很多灵活性。例如,
threadpoolexecutor
有一个需要做的工作的队列。如果该队列已满,它可能会迫使呼叫者运行工作以防止队列溢出。@Async的设计更易于使用,但是在执行方式上采用了很多控制。另外,代码变为特定于弹簧,因此在更广泛的分布式库中使用不合适。
Executors are more complex to use, but offer a lot of flexibility on how the function is run. For example, a
ThreadPoolExecutor
has a queue of the work it needs to do. If that queue is full, it can force the caller to run the work to keep the queue from overflowing.@Async is designed to be simpler to use, but takes aways a lot of the control you have in how the execution happens. Also, the code becomes Spring specific, so it wouldn't be appropriate to use in a more widely distributed library.