• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Thread exit question

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Reasonable. Thx
 
reply
    Bookmark Topic Watch Topic
  • New Topic