Oracle
1Z0-895 · Question #24
Which two statements are correct about stateless session beans? (Choose two.)
The correct answer is A. The bean class may declare instance variables. C. The container may use the same bean instance to handle multiple business method invocations at the same. A: Stateless session beans are EJB's version of the traditional transaction processing applications, which are executed using a procedure call. The procedure executes from beginning to end and then returns the result. Once the procedure is done, nothing about the data that was…
Server Installation and Configuration
Question
Which two statements are correct about stateless session beans? (Choose two.)
Options
- AThe bean class may declare instance variables.
- BThe lifetime of the bean instance is controlled by the client.
- CThe container may use the same bean instance to handle multiple business method invocations at the same
- DThe container may use the same bean instance to handle business method invocations requested by
How the community answered
(54 responses)- A85% (46)
- B9% (5)
- D6% (3)
Explanation
- A: Stateless session beans are EJB's version of the traditional transaction processing applications, which are executed using a procedure call. The procedure executes from beginning to end and then returns the result. Once the procedure is done, nothing about the data that was manipulated or the details of the request are remembered. There is no state. These restrictions don't mean that a stateless session bean can't have instance variables and therefore some kind of internal state. There's nothing that prevents you from keeping a variable that tracks the number of times a bean has been called or that tracks data for debugging. An instance variable can even hold a reference to a live resource like a URL connection for writing debugging data, verifying credit cards, or anything else that might be useful. C:A stateless session bean is relatively easy to develop and also very efficient. Stateless session beans require few server resources because they are neither persistent nor dedicated to one client. Because they aren't dedicated to one client, many EJB objects can use just a few instances of a stateless bean. A stateless session bean does not maintain conversational state relative to the EJB object it is servicing, so it can be swapped freely between EJB objects. As soon as a stateless instance services a method invocation, it can be swapped to another EJB object immediately. Because there is no conversational state, a stateless session bean doesn't require passivation or activation, further reducing the overhead of swapping. In short, they are lightweight and fast! The Lifecycle of a Stateless Session Bean Because a stateless session bean is never passivated, its lifecycle has only two stages: nonexistent and ready for the invocation of business methods. The EJB container typically creates and maintains a pool of stateless session beans, beginning the stateless session bean's lifecycle. The container performs any dependency injection and then invokes the method annotated @PostConstruct, if it exists. The bean is now ready to have its business methods invoked by a client. At the end of the lifecycle, the EJB container calls the method annotated @PreDestroy, if it exists (not B). The bean's instance is then ready for garbage
Topics
#stateless session bean#instance variables#bean pooling#concurrency
Community Discussion
No community discussion yet for this question.