| Author |
Thread Question
|
Simran Dass
Ranch Hand
Joined: Jan 09, 2010
Posts: 183
|
|
Given the foll Question -
The options are (Choose 1): -
A) Prints "ready to print , now printing" without any exception
B) Prints "ready to print , now printing,printed" without any exception
c) Run time Exception
d) Compiler error
Answer is a).
Should not it be unpredictable bec' result can be either : -
Prints "ready to print , now printing" without any exception OR
Prints "now printing ,ready to print " without any exception
|
 |
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
|
|
Simran Dass wrote:
Given the foll Question -
There are too many typos and errors present to tell just what this will do. Even if I fix them to get this to compile, the run method is never called as start is not called on any thread.
Edit:
Except, if you do happen to call start on t immediately after it was created, then you'll see your results.
Question: what object is domore synchronized to? What object gets the called with notifyAll()?
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
pete stein wrote:
Simran Dass wrote:
Given the foll Question -
There are too many typos and errors present to tell just what this will do. Even if I fix them to get this to compile, the run method is never called as start is not called on any thread.
Edit:
Except, if you do happen to call start on t immediately after it was created, then you'll see your results.
Question: what object is domore synchronized to? What object gets the called with notifyAll()?
I think, your question should be like this.
Output :
Now printing
Ready to print
And waiting for a notification, since this will not be notified in future, We have to forcefully exit the code.
|
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
|
 |
 |
|
|
subject: Thread Question
|
|
|