• Post Reply Bookmark Topic Watch Topic
  • New Topic

Call a particular Thread

 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was being asked to me in one of the interviews:
Lets consider an scenario where in there are few threads of same priority. Lets Say, I want Thread T1 , to execute till a particualr point, and then i want Thread T2 to exectue. I was asked how can i implement that. I thought using wait() and notify may be the best way to do this.

but then the interviewer told me that (which i knew) that is not necessary for the Thread Scheduler to pick up T2 , when i call wait() on T1. Could anyone please tell me is there any way where in i can ensure that Thread t2 executes for sure....
 
Rok Ć telcer
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Maan Suraj wrote: Could anyone please tell me is there any way where in i can ensure that Thread t2 executes for sure....

With a help of Thread.join().

edit: This means, that after each Thread[i].start(), you would have to call Thread[i].join().


Regards,
Rok
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! but he was not exactly looking for Thread.join(). I answered that, but still he told there is no guarantee that T2 will execute for sure. I told him that its all dependent on Thread Scheduler, and best thing we can do is we can set priority of T2 Higher than others.

so any other answer?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!