This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action 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 thread safety and concurrent access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "thread safety and concurrent access" Watch "thread safety and concurrent access" New topic
Author

thread safety and concurrent access

Siddharth Raja
Greenhorn

Joined: Nov 11, 2013
Posts: 18


is the variable 'x' prevented from concurrent access
is the above code thread safe?

if the following output had to be guaranteed, what changes should be made to the code?
main: 0
Thread-0: 1 or Thread-1: 1
Thread-1: 3 or Thread-0: 3
main: 4
Myyron Murray Latorilla
Ranch Hand

Joined: Dec 10, 2009
Posts: 65

Not thread safe, because your code just locks on different instance of "tester" class.


OCPJP6
 
 
subject: thread safety and concurrent access