• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

which is thread safe ?

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic