• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

thread's

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question removed ... it was identified as being a real exam question... Jane
Let me know the right one,state the resoning behind your chosen one.

[This message has been edited by Jane Griscti (edited May 12, 2001).]
 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mr william's,
This fraternity is realy putting some of the challenging question's in this forum.Could u please put forward your opinion on this question.I will be taking my exam in the next two day's, please come forward with something on this.I have chosen option D.Is that right?
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dear lawson,
what i feel is
choice a) is not true:check() can return true
choice b) is not true:setXY(int i)sets same value for x and y and check retun false.
choice c)can be true(am i right?)
choice d): (is it the only way)
jeena jose
 
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I choosed answer 'A':

  1. correct, since the only public is setXY and check(), so outside of the class can only access those method which is either seting the value x & y are call check(), and hence check() will always return false.
  2. in-correct, when one thread call setXY, it will call setX and it will get the lock of SyncTest, other thread must wait for the lock, hence x & y always same, and check will return false.
  3. in-correct, setX & setY is private.
  4. in-correct, it could be correct, but i assumed the parameter 'i' in setX(int i) & setY(int i) will get the same value, hence check() is still return false. so i prefere to select answer A.

  5. i hope i choosed the correct answer !
    stevie
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems to me that there is a possibility for check to return true, if Thread A calls setX and returns (releasing the lock) but Thread B is allowed to call check() before A can call setY.

public void setXY (int i) {
setX(i); // setX is synchronized
setY(i); // setY is synchronized
}
public synchronized boolean check() {return X != Y; }
But this does not exactly match any of the options because the critical point is not the number of Threads calling setXY, but the fact that check is being called while a Thread calls setXY. If I had to pick an option I would pick B.
Bill

------------------
author of:
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
i fully agree with Steve that b & c are incorrect & can't be right . The reasons he gives , i believe are quite explicit & clear. I also agree with his assertion that option a is also correct ( I agree with his reason that incrementation occurs via a single method) . however i feel that option d is also correct because consider the following scenario :- A Thread calls setX() & immediately afterwards call check() without calling setY. In this case check() should return true.
what do u ranchers feel ? Pls do post u'r comments.
Regards
kaushik
kaushik
 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agreed with William, suppose 2 different threads call the setXY() and check() respectively without stop, I think there's the chance check() return true. the chance is that check() happens to execute between setX() and setY() since the lock is released at the interval and other synchronized method could be entered.
James
reply
    Bookmark Topic Watch Topic
  • New Topic