• Post Reply Bookmark Topic Watch Topic
  • New Topic

thread coming out of waiting

 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a thread which i have put on wait for 1millisecond ,

synchronized(this)
{
Thread t=new Thread();
t.start();
this.wait(1); /** currently executing thread waits for 1millisecond */
{
// some logic on thread 2 gets executed
}
//Location 2
}
My problem is if the logic on thread t is slow in responding and time out for this.wait(long timeout ) occurs , where will the control be placed in the code. Is it placed at location 2
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving thread as too difficult for "beginning".
 
Henry Wong
author
Sheriff
Posts: 22542
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ragi singh wrote:
My problem is if the logic on thread t is slow in responding and time out for this.wait(long timeout ) occurs , where will the control be placed in the code. Is it placed at location 2


First, since there isn't any thread that notifies the waiting thread, the exit condition, for the wait, is always by timeout.

Second, the new thread doesn't do anything in this example, so it doesn't matter if it is "slow in responding" or not.


And third, regardless of return by notification or return by timeout, control doesn't change -- it behaves like any other method call. The next line will execute next.

Henry
 
ragi singh
Ranch Hand
Posts: 198
Oracle Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah thanks , i think i should have used t.join(long milliseconds) instead . Would you comment
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!