@Async和executor之间的区别

发布于 2025-02-05 08:34:47 字数 62 浏览 0 评论 0原文

我找不到使用执行人而不是@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青春有你 2025-02-12 08:34:47

执行者使用更复杂,但在运行函数的方式上提供了很多灵活性。例如,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文