File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread exit question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread exit question" Watch "Thread exit question" New topic
Author

Thread exit question

Alan Mar
Greenhorn

Joined: Oct 15, 2001
Posts: 21
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)

----SCJP Java 2----
Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
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

Joined: Oct 15, 2001
Posts: 21
Reasonable. Thx
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread exit question