• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Mock Question

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import javax.servlet.*;
import javax.servlet.http.*:
public class TestServlet extends HttpServlet implements SingleThreadModel {
private HashMap hm = new HashMap();
public void doGet(HttpServletRequest req, HttpServletResponse res) {
//lot of code.
}
}

Which of the following statements are correct?

a) 'hm' is thread safe
b) 'hm' is not thread safe
c) 'req' is thread safe
d) Making 'hm' static would make it thread safe.
e) 'hm' can be made thread safe only if it is made final.

Ansewrs given is a) and c)

How come a) is correct? In SingleThreadModel it may create more than one instance right??
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when servlet implement STM interface,the servlet container will create more than one instance when some request receive.

so A is right.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instance variables are thread safe only when you implement SingleThreadmodel hence a is correct
 
reply
    Bookmark Topic Watch Topic
  • New Topic