This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes which is thread safe ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "which is thread safe ?" Watch "which is thread safe ?" New topic
Author

which is thread safe ?

jawwad ahmed
Ranch Hand

Joined: Dec 01, 2001
Posts: 179
Well while not implementing which is thread safe.
public class First extends HttpServlet
{
String str=new String("jawwad");//1
public void doGet(HttpServletRequest req,HttpServletResponse)
{
ServletConfig config=getServletConfig();//2
String s1=config.getInitParameter("one");//3
ServletContext context=getServletContext();//4
String s2=context.getInitParameter("two");//5
}
}
Select any two.Which reference assigned is thread safe.
Ian B Anderson
Ranch Hand

Joined: Jun 26, 2001
Posts: 275
Hello,
This seems very tough and I could be wrong but here goes...
1) is definetly not thread safe as it is an instance variable
2) I would say say this is thread safe because it is used to pass initialization params to a Servlet etc.
3) I would say 3 is safe because there is no setInitParameter so in theory this is the same while the server is running
4) I would say this isn't thread safe because it returns the ServletContext in which the event took place. Also stores info about the environment in which the Servlet is running. Different events so possible threading issues. (I could be wrong here!).
5) I would say this isn't thread safe because you get different SerletContexts on different VMs (Once again I could be wrong!)

So my final answer would be 2 and 3 are thread safe.
Ian


<a href="http://www.INESystems.com/scbcd/" target="_blank" rel="nofollow">http://www.INESystems.com/scbcd/</a> - SCBCD Exam simulator<br /><a href="http://www.INESystems.com/scbcd/" target="_blank" rel="nofollow">http://www.INESystems.com/scea/</a> - SCEA Exam simulator
 
wood burning stoves
 
subject: which is thread safe ?
 
Similar Threads
isThreadSafe is false for Single Thread Model?
How to make a class thread safe
Question about Thread-safe
SingleThreadModel Servlet with class variable
Urgent : Thread Safe