Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thread safety and concurrent access

 
Siddharth Raja
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 65
Eclipse IDE Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not thread safe, because your code just locks on different instance of "tester" class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic