This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso 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 The Software Craftsman this week in the Agile 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.

wood burning stoves
subject: thread safety and concurrent access