• Post Reply Bookmark Topic Watch Topic
  • New Topic

A question wait/notify

 
Barry Brashear
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a loop which does some processing on item in a vector. After each
one I have a wait. The loop looks like this the following. The problem is
it is only processing the first one. In another method I am setting
available to true. That code is executing. What am I missing?

for(int a=0; a<vector.size(); a++)
{
available = false;
process(vector.elementAt(a);

while(available==false)
{
try
{
wait();
}
catch(InterruptedException ie)
{
ie.printStackTrace();
}
}
}
 
Aditya Jha
Ranch Hand
Posts: 227
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will be a help if you could post the piece of code where notify() is being called (I hope 'available' is a shared variable and is being assigned the value 'true' over there).
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To add to Aditya's response, if a process invokes wait(), it will not execute until another process executes notifyAll() or notify() to tell the waiting process that the reserved resources have been freed and are available for used by whatever thread the scheduler starts next.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!