aspose file tools*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: which is thread safe ?