This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread 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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "thread safety and concurrent access" Watch "thread safety and concurrent access" New topic

thread safety and concurrent access

Siddharth Raja

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.

I agree. Here's the link:
subject: thread safety and concurrent access
Similar Threads
why is it wrong?
static void main(String args[]) is working why??????
What is the output