• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread-safety

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm a Java newbie writing a small web application. I've been reading K&B's HF Servlet and JSP book at night in my attempt to catch up on the technology. Anyway in chapter 5, Kathy makes it very clear that servlet instance variables are not thread-safe. I understand that. But what I'm not clear on is what about instance variables of new'ed POJ classes? If my servlet instantiates a class containing instance variables, are those instance variables thread-safe? jd
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, unless you do something like store a reference to them in a servlet instance variable.

When you instantiate an object and store it in a thread-safe reference, such as a method-local variable, other threads have no way to "get at" the instance. Ergo, thread-safe.
[ October 19, 2006: Message edited by: Bear Bibeault ]
 
John Daniel
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, that's what I wanted to know. jd
 
reply
    Bookmark Topic Watch Topic
  • New Topic