保证@Singleton @Startup @PostConstruct方法在使EJB可用于客户端调用之前返回? [英] @Singleton @Startup @PostConstruct method guaranteed to return before EJBs made available for client calls?

查看:133
本文介绍了保证@Singleton @Startup @PostConstruct方法在使EJB可用于客户端调用之前返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WebSphere 8.0上运行的Java EE 6应用程序的上下文中,我需要先执行许多启动任务,然后才能执行任何业务方法.为此,使用@Startup @Singleton bean似乎是一个有前途的解决方案.但是,对我来说,尚不完全清楚应用程序生命周期的样子. EJB 3.1规范指出以下内容:

In the context of a Java EE 6 application run on WebSphere 8.0, I need to execute a number of startup tasks before any business method can be executed. Using a @Startup @Singleton bean for this purpose seems like a promising solution. However, it is not entirely clear to me how exactly the application lifecycle would look like. The EJB 3.1 spec states the following:

默认情况下,容器负责决定何时 初始化一个Singleton bean实例.但是,bean开发人员可以 (可选)配置Singleton以进行初始化.如果 启动注释出现在Singleton bean类上,或者如果 通过部署描述符将Singleton指定为 需要急切的初始化,容器必须初始化 应用程序启动过程中的Singleton bean实例. 容器必须在初始化之前将所有此类启动时间Singleton初始化 任何客户端请求都将传递到以下任何企业Bean组件中: 该应用程序.

By default, the container is responsible for deciding when to initialize a Singleton bean instance. However, the bean developer can optionally configure the Singleton for eager initialization. If the Startup annotation appears on the Singleton bean class or if the Singleton has been designated via the deployment descriptor as requiring eager initialization, 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.

  1. 在最后一句话中,初始化"的确切含义是什么?在使企业Bean可用于客户端请求之前,容器将等待@Startup Bean的@PostConstruct方法返回吗?

  1. In the last sentence, what exactly constitutes "initialization"? Will the container wait for the @PostConstruct method of the @Startup bean to return before making enterprise beans available to client requests?

说到客户端请求",在这种情况下,使用@Scheduled注释的EJB方法的预定执行是否算作一次?

Speaking of "client requests", do scheduled executions of an EJB method with the @Scheduled annotation count as one in this context?

我需要保证在运行应用程序的各种EJB中的任何业务方法之前,无论是通过客户端调用还是计划执行,都必须在应用程序启动时执行一些代码.在@Singleton @Startup bean的@PostConstruct方法内运行启动代码是否提供了这样的保证?如果没有,还有其他方法可以保证这种行为吗?

I need to guarantee that some code is executed on application startup before any of the business methods in any of the application's various EJBs can be run, be it through client calls or scheduled executions. Does running the startup code inside the @PostConstruct method of a @Singleton @Startup bean provide such a guarantee? If not, is there any other way to guarantee this behavior?

推荐答案

  1. 是的,容器在允许任何客户端请求之前,等待模块("EJB应用程序")中所有@Startup bean的@PostConstruct方法返回.
  2. 是的,主题为单例bean中的PostConstruct方法可以创建EJB计时器.死锁,PostConstruct方法一定不能等待EJB计时器运行".换句话说,计时器回调调用将等待@PostConstruct方法完成,因此@PostConstruct方法一定不能等待计时器回调调用完成.
  1. Yes, the container waits for the @PostConstruct method of all @Startup beans in the module ("EJB application") to return before allowing any client requests.
  2. Yes, this is the case in WebSphere Application Server as implied by the Developing singleton session beans topic in the Knowledge Center, which says "A PostConstruct method in a singleton bean can create an EJB timer [...] However, to avoid a deadlock, the PostConstruct method must not wait for an EJB timer to run". In other words, timer callback invocations will wait for @PostConstruct methods to complete, so @PostConstruct methods must not wait for timer callback invocations to complete.

这篇关于保证@Singleton @Startup @PostConstruct方法在使EJB可用于客户端调用之前返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆