This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

class level private variables thread safe?  RSS feed

 
Anil
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Can someone tell me if the class level private variables are thread safe?

Thanks,
Anil
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anil --

Welcome to JavaRanch!

First, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. Joke names, obviously fake names, and "handles" aren't OK here. You can change your display name here. Thanks!

As to your question: no, not intrinsically. All member variables -- both class and instance variables -- need to be properly protected from concurrent access.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They're only as safe as you make them, and there are many ways to make them unsafe. For example there's nothing safe about passing one instance variable to two other threads. There's nothing safe about two threads calling a method on your object which happens to reference an instance variable. You have to synchronize the method or use another lock to make them safe. Does that ring true?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!