• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone clarify it? (True or False)
JVM exits after the main() thread is exited even if there might be some threads running.
under which conditions will a currently executing thread stop
a.when an interrupted exception occurs
b.when a thread of higher priority is ready(becomes runnable)
c.when the thread creates a new thread
d.when the stop() method is called.
e.when wait() method is called
My ans is a,b,d,e
But I am not sure.
Thanks

 
paul wheaton
Trailboss
Posts: 22046
Firefox Browser IntelliJ IDE Java
 
Debanjana Dasgupta
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)True
2)d--will cause a thread to stop.
a.when an interrupted exception occurs
Interrupted Exception doesnt cause a thread to stop--it can run again.
b.when a thread of higher priority is ready(becomes runnable)
it is not neccessory that the this Thread will stop. It depends on the JVM
e.when wait() method is called
The thread will stop if that thread calls wait() on any object and the moniter of that object is not available
and not if somebody else calls wait() method on it.
 
Anand Kaimal
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1)True
main() thread is exited when all user threads exit.
so the"some threads running." would be only Deamon thread, which automatically exits.
2) I feel that both d & e are correct.
Some body please clarify me.
 
ricky gonzalez
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, when you said that the "thread" can run again even after InterruptedException occurs, do you mean the same thread object, or another object of that thread re running again?
Thanks.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am moving this topic to Threads and Synchronization
Ajith
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


JVM exits after the main() thread is exited even if there might be some threads running.

FALSE
JVM exits when there are no more non-dameon threads running. and It's quite possible that although main thread has exited. but there are some non-dameon threads which are still running and in this case JVM will continue.
so the above statement is false.
regards
deekasha
 
Mapraputa Is
Leverager of our synergies
Sheriff
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ricky:
�Interrupted Exception doesnt cause a thread to stop - it can run again�, yes, �it� means the same thread object.
I would say InterruptedException MAY cause a thread to stop, but to say WILL is incorrect, it may or may not.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!