nerdexam
Oracle

1Z0-899 · Question #177

Given that a web application consists of two HttpServlet classes, ServletA and ServletB, and the ServerletA.service method: 20. String key = "com.example.data"; 21. session.setAttribute(key…

The correct answer is C. ensure that ServletB synchronizes on the session object when setting session attributes E. enclose lines 21-22 in synchronized block. See the full explanation below for the reasoning.

Question

Given that a web application consists of two HttpServlet classes, ServletA and ServletB, and the ServerletA.service method: 20. String key = "com.example.data"; 21. session.setAttribute(key, "Hello"); 22. object value = session.getAttribute(key); 23. Assume session is an HttpSession, and is not referenced anywhere else in ServletA. Which two changes, taken together, ensure that value is equal to "Hello" on line 23? (Choose two)

Options

  • Aensure that the ServletB.service method is synchronized
  • Bensure that the ServletA.service method is synchronized
  • Censure that ServletB synchronizes on the session object when setting session attributes
  • Denclose lines 21-22 in synchronized block:
  • Eenclose lines 21-22 in synchronized block:

How the community answered

(40 responses)
  • A
    10% (4)
  • B
    3% (1)
  • C
    85% (34)
  • D
    3% (1)

Community Discussion

No community discussion yet for this question.

Full 1Z0-899 Practice