File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
It's not a secret anymore!