File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes Valentin's Question 52 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Mock Exam Errata
Reply Bookmark "Valentin Watch "Valentin New topic
Author

Valentin's Question 52

Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
While I agree with the results, I don't agree with the explanation of question 52.

This scenario doesn't happen:
Imagine the following scenario: t1 starts, it invokes aMethod. i is now 1. t1 releases the lock associated with a and the scheduler decides that it is the turn of t2 to run. t2 invokes aMethod and i's value is now 2.


The code actually creates two Question52 objects, each with its own A object.

The instance methods aMethod() and bMethod() synchronize on the current instance of A. Since ++ and -- are not thread-safe, threads t1 and t2 could easily corrupt static variable i during their combined 20,000,000 executions.


Mike Gershman
SCJP 1.4, SCWCD in process
 
 
subject: Valentin's Question 52
 
Threads others viewed
Deadlocks in Threads?
A question about using Join in Thread.
Strings
Thread
Tests for the Data class/locking mechanism
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture