• Post Reply Bookmark Topic Watch Topic
  • New Topic

Confustion in threads again !  RSS feed

 
Deepak M
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the followidng statements are true.
a.All the threads created in a class come to an end at the same time.
b.You can stop a thread indefinitely if u wish to.
c.You can start a thread only by extending the Thread class d.multiple threads accessing a method will lead to producing junk.
e.JVM exits after the main() thread is exited even if there might be some threads running
Is 'd' right or wrong ?
I think the right answers are : b, e
 
rajsim
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
e. is wrong. JVM usually exits only when all user threads finish.
d. multiple threads accessing a method will lead to producing junk
is ambiguous.
You can say that multiple threads accessing a method of the same object might produce junk (unpredictable results) if no proper synchronization is done
 
Marcela Blei
Ranch Hand
Posts: 477
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that B is ambiguous too, because you can stop a thread with interrupt if you have it sleeping or waiting (correct me if I am wrong)
About e: Look at the setDaemon definition.: the JVM finishes when there are non Daemon threads not running. Threads that are non Daemon are called user threads.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!