You are not logged in.
#1 2015-11-06 11:01:49
Which variables reference objects that are thread-safe?
Java Quizzes SCWCD (Sun Certified Web Component Developer)
Question:
public class MyServlet extends HttpServlet{
private StringBufer abc = new StringBufer ("abc"); // 1
private static StringBufer xyz = new StringBufer(); // 2
public void doPost (HttpServletRequest req, HttpServletResponse resp) { // 3
String str = "Hello...";// 4
HttpSession session = req.getSesion();//5
}
}
Which variables reference objects that are thread-safe?
Option A):
String at line marked as 4
Option B):
session at line marked as 5
Option C):
Request at line marked as 3 and String at line marked as 4
Option D):
Request at line marked as 3
Option E):
None of these
Correct Answer is Option C):
Request at line marked as 3 and String at line marked as 4
Explanation:
Only local variables and request variables are thread safe in servlet. Session is not thread safe because, user can open two browser windows and keep the same session for both the browsers. Always instance variables are not thread sage.
Online Web Tutorials And Interview Questions With Answers Forum:
https://globalguideline.com/forum/
Offline
2015-11-06 11:01:49
- Advertisement
- Ads By Google
Re: Which variables reference objects that are thread-safe?
\n