Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

which is thread safe ?

 
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
When all four tires fall off your canoe, how many tiny ads does it take to build a doghouse?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic