Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

choose one correct ans. -thread

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the following statements is valid?
A.The JVM runs till the main method exits, even if there are other user threads running.
B.An InterruptedException occurs when the sleep() method is called on a thread.
C.A thread can be suspended for an indefinite duration of time.
D.A thread can be made in Java only by subclassing the Thread class.
E.The synchronize keyword can be used only in a method that is part of a class that is derived from Thread.
I think ans. is E, Please confirm it.
Jyotsna
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer is C.
E is wrong because any class can have synchronized methods.
 
Jyotsna Umesh
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thomas, I beleive suspended method is deprecated in Java2 so do you still think option c is right?
Jyotsna
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say c also, it's the only one that isn't false.
It could be none but that would depend on how they meant 'suspended': if they meant with the actual suspend() method then technically, even though it's deprecated, it still works. If by suspend they menat not running then sleep(), wait() or yield() would do it too.

Dave
 
Jyotsna Umesh
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thomas, Dave ,I think you are right. But the option E is wrong because of the word ONLY. Am I right?
Jyotsna
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A is wrong because the JVM continues to run until the last thread dies.
B is wrong because sleep does not generate an InterruptedException.
D is wrong because a thread can also be made by implementing the Runnable interface.
E is wrong because sychronize can be used on any method.
C is correct because a thread suspension by the JVM is implementation specific and the order that threads run cannot be guaranteed - only indicated by priority. Also the order in which threads run is not possible to determine. The question does not mention the suspend() method at all although the wording is somewhat off-putting.
Hope this helps.
Cheers
Tony
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic