This week's book giveaways are in the iOS and Features new in Java 8 forums.
We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Static variable" Watch "Static variable" New topic

Static variable

rex tony
Ranch Hand

Joined: Aug 29, 2007
Posts: 159
Static variable Is Thread Safe?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14584

No, static variables are not automatically thread-safe. You'll have to take care of synchronization if you have multiple threads that are accessing a static variable simultaneously.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
camelia codarcea
Ranch Hand

Joined: May 08, 2007
Posts: 36

Static variable should be changed inside static syncronised methods in order to be thread-safe.
Two threads that access a static syncronized method, will always block each other, regardless if they are using the same instance or two different instances.

SCJP 5.0 .... 97%
I agree. Here's the link:
subject: Static variable