About Question enthuware.ocpjp.v7.2.1553 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
DesRenthuware
Posts: 32
Joined: Wed Aug 28, 2013 6:12 am
Contact:

About Question enthuware.ocpjp.v7.2.1553 :

Post by DesRenthuware »

Hi

Just trying to clarify for my own understanding, exactly what is happening here:

1. There are essentially three classes here - Mumbo, Jumbo and TestClass.
2. Mumbo and Jumbo are inner classes, with Jumbo extending Thread.
3. On execution, main() instantiates TestClass via its constructor.
4. This creates instances of the inner classes defined inside TestClass.
5. Next the constructor starts the Jumbo instance running as a separate thread.
6. The constructor then invokes sleep() on the main thread for a second.
7. By the time we return from sleep, the following processing has occurred on the Jumbo thread:

- the run() method for the Jumbo instance has been invoked.
- the Jumbo thread invokes the instance method doIt() defined in the Mumbo instance.
- As this method is synchronized, a lock is obtained on the Mumbo object.
- Inside the try/catch, the (Mumbo) wait() method is invoked, resulting in the lock on the Mumbo object being released???

8. We return to the TestClass constructor where we use a synchronized code block to gain a lock on the Mumbo object.
9. We then invoke the notifyAll() method on the Mumbo instance, which notifies any waiting threads to start again.
10. The constructor releases the lock on the Mumbo object and exits the main thread.
11. Having awoken from the wait(), the lock on the Mumbo instance is re-acquired inside doIt() by the Jumbo thread.
12. The "done" message prints and we exit.

Is that right?

admin
Site Admin
Posts: 10062
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1553 :

Post by admin »

Yes, you are right :)

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

DesRenthuware
Posts: 32
Joined: Wed Aug 28, 2013 6:12 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1553 :

Post by DesRenthuware »

Thank you!

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 111 guests