• Post Reply Bookmark Topic Watch Topic
  • New Topic

a puzzling thread code.

 
Arun Martin
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
this question is from one of the mock exams.
question:

What is the purpose of invoking notify() in method doIt()?
options:
-------
1. changes all class methods to synchronized until release() is invoked
2. informs other threads that this thread has completed doIt()
3. informs waiting threads it has released the object's monitor
4. nothing, unless notify() was overridden from its java.lang.Object
5. depends on how notify() method is defined in this class
could u please tell me how this code works?.
arun.
You should use [ CODE] tag at the beginning of the code and [ /CODE] tag at the end of the tag to make your code look good.
Thanks

[This message has been edited by Rahul Mahindrakar (edited December 07, 2000).]
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun,
The answer is 3 as
Part I

The above code checks for a condition for a thread to proceed if the condition is true then the thread waits for the condition to become false before it tries again.
Part II

This part of the code does some work and then notifies other thread to check up if otherMethod() returns false for it to work.
This type of code is often called a before- after pattern in the sense that
before();
do();// do some work
after();// check up if the work done is correct
Though in the model given there is no after pattern.
In the before() method i check up some condition ; if the condition is correct i do some work else do something do something else like throw an exception
In the after() method i checkup the condition again like the before() method and again exit if things are ok else throw an exception.

[This message has been edited by Rahul Mahindrakar (edited December 07, 2000).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!