gpt4 book ai didi

java - @Singleton @Startup 完全异步?

转载 作者:太空宇宙 更新时间:2023-11-04 08:29:20 27 4
gpt4 key购买 nike

我正在使用 @Singleton 和 @Startup 注释来创建一个长时间运行的进程。通过使用这些注释,我可以安全地假设我的进程将是完全异步运行的单个线程吗?

最佳答案

您可以仅在类级别使用这些注释,因此我不确定您指的是哪个“过程”(@PostConstruct 方法?)

我不记得 EJB 3.1 规范中任何涉及所需的异步单例初始化的部分。

4.8.1 单例初始化:

(...)the bean developer can optionally configure the Singleton for eager initialization. If the Startup annotation appears on the Singleton bean class (...) the container must initialize the Singleton bean instance during the application startup sequence. The container must initialize all such startup-time Singletons before any client requests are delivered to any enterprise bean components in the application.

这取决于应用服务器供应商选择什么初始化技术。 我不会假设加载将在单独的进程中发生,而只是假设它将在服务器启动期间和为客户端提供服务之前发生。

从评论中输入:为您的耗时操作提供一个单独的异步 EJB 方法(将从单例初始化器 EJB 中调用)怎么样?

关于java - @Singleton @Startup 完全异步?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7841991/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com