Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

class level private variables thread safe?

 
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: 24213
35
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?
 
I think I'll just lie down here for a second. And ponder this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!