File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Question

 
Simran Dass
Ranch Hand
Posts: 183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic