Which represents the output generated from FooEJB after the deployment has completed?

Given Singleton bean FooEJB:

FooEJB is packaged as the only bean in an ejb-jar and deployed to a server instance. Which
represents the output generated from FooEJB after the deployment has completed?

Given Singleton bean FooEJB:

FooEJB is packaged as the only bean in an ejb-jar and deployed to a server instance. Which
represents the output generated from FooEJB after the deployment has completed?

A.
Init

B.
foo

C.
Init foo

D.
<no output>

E.
a or d

Explanation:
Note:
*The PostConstruct annotation is used on a method that needs to be executed after dependency
injection is done to perform any initialization. This method MUST be invoked before the class is
put into service. This annotation MUST be supported on all classes that support dependency
injection. The method annotated with PostConstruct MUST be invoked even if the class does not
request any resources to be injected. Only one method can be annotated with this annotation. The
method on which the PostConstruct annotation is applied MUST fulfill all of the following criteria – -The method MUST NOT have any parameters except in the case of EJB interceptors in which
case it takes an InvocationC ontext object as defined by the EJB specification. – The return type of
the method MUST be void. – The method MUST NOT throw a checked exception. – The method
on which PostConstruct is applied MAY be public, protected, package private or private. – The
method MUST NOT be static except for the application client. – The method MAY be final. – If the
method throws an unchecked exception the class MUST NOT be put into service except in the

case of EJBs where the EJB can handle exceptions and even recover from them.
*PostConstruct methods are invoked on the newly constructed instance, after any dependency
injection has been performed by the container and before the first businessmethod is invoked on
the bean.



Leave a Reply 7

Your email address will not be published. Required fields are marked *


Alex

Alex

Could be D. To ensure A it needs @Startup
Enterprise JavaBeans 3.1, Final Release: 4.8.1 Singleton Initialization
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.

Oscar

Oscar

Could be D, but I think is E.

atef30

atef30

Could be D,Lazy is the default strategy.

Leo

Leo

I did a test and the container only executed init() if I add the @Startup annotation. So the correct answer is D

Figaro

Figaro

If the Startup annotation appears on the Singleton bean the container must initialize the Singleton bean instance during the application startup sequence, but container can construct instance of singleton bean on its own during deployment of the bean.
So in my opinion the correct answer is E.