Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Bastet Massri   on Jan 22 In Java Category.

  
Question Answered By: Rocco Anderson   on Jan 22

1. Your program  does not wait forever in this case because you are telling your
ThreadTest thread to wait. The main JVM thread is not waiting and once that
finishes, the program finishes, no matter what your ThreadTest thread is doing.
2. Your program waits forever in this case because you are telling the main JVM
thread to wait and nothing ever notifies it to wake up and finish. I explained
this in the previous email; I quote myself:

"There's the main thread which is started by the JVM and the thread class that
you create. Your thread will never run  if you never call the start  method. So
when you call waitTest, the only thread you are telling to wait is the main JVM
thread. That thread will then wait indefinitely because there is no other
thread that can notify it to stop."

I answered both of your questions in the previous email. I suppose you didn't
read it. And as to your question  about having a thread suspend itself, yes that
is possible, but not in the way that you think. But I will tell you that you're
going to have a really difficult time using threads if you don't understand how
they work.

Share: 

 

This Question has 5 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on A challenging question about Threads&Synchronization Or get search suggestion and latest updates.