1Z0-899 · Question #167
A servlet class is injected with a JDBC data source. After injection has occurred, the servlet needs to create a cache out of some of the data in the database, so as to improve responsiveness. Which…
The correct answer is A. Servlet.init() D. A method annotated with @PostConstruct. A: Because the Servlet init() method is invoked when the servlet instance is loaded, it is the perfect location to carry out expensive operations that need only be performed during initialization. By definition, the init() method is thread-safe. The results of operations in the…
Question
Options
- AServlet.init()
- BServlet.destroy()
- CA method annotated with @Init
- DA method annotated with @PostConstruct
- EA method annotated with @PreDestroy
- FA method annotated with @Resource
How the community answered
(47 responses)- A81% (38)
- B2% (1)
- C9% (4)
- E6% (3)
- F2% (1)
Explanation
A: Because the Servlet init() method is invoked when the servlet instance is loaded, it is the perfect location to carry out expensive operations that need only be performed during initialization. By definition, the init() method is thread-safe. The results of operations in the HttpServlet.init() method can be cached safely in servlet instance variables, which become read- only in the servlet service method. private void init() { cached = (Cached) ctx.lookup(EJB_PATH + Cached.class.getSimpleName());
Topics
Community Discussion
No community discussion yet for this question.