Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread exit question

 
Alan Mar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused with the below question, please tell me which are correct answers.
1.Which two cannot directly cause a thread to stop executing?
A. exiting from a synchronized block
B. calling the wait method on an object
C. calling the notify method on an object
D. calling the read method on an InputSteam object
E. calling the setPriority method on a thread object
(I pick A,C,D)
----------------------------------------------------------
2. Given:
public class SynchTest{
private int x;
private int y;
public void setX(int I){x=I;}
public void setY(int I){y=I;}
public synchronized void setXY(int I){setX(i);setY(i);}
public synchronized boolean check(){return x!=y;}
Under which conditions will check() return true when called from a different class?
A. check() can never return true
B. check() can return true when setXY is called by multiple threads
C. check() can return true when multiple threads call setX and setY deparately
D. check() can only return true if SynchTest is changed to allow x and y to be set separately
(I pick A,D)
 
Ragu Sivaraman
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1:
I believe the answers are A,D
I am not really sure about the C
read() may block the thread if the data to be read is not available
Q2: I have to pick A,D
This code doesnt implement Runnable or extends Thread
so i dont think B and C would be correct
Please do correct me if i am wrong
Ragu
[This message has been edited by Ragu Sivaraman (edited October 15, 2001).]
[This message has been edited by Ragu Sivaraman (edited October 15, 2001).]
[This message has been edited by Ragu Sivaraman (edited October 15, 2001).]
 
Alan Mar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reasonable. Thx
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic