title: why does my notify() not wake a waiting thread?
body: <p>I have a simple multithreaded algorithm designed to load a series of files in a background thread, and have a JPanel display the first image as soon as it is done loading.  In the constructor of the JPanel, I start the loader, then wait on the list of images, as follows:</p>
  
  <pre><code>//MyPanel.java
  public ArrayList&lt;BufferedImage&gt; images = new ArrayList&lt;BufferedImage&gt;();
  int frame;    
  
  public MyPanel(String dir){
      Thread loader = new thread (new Loader(dir, this));
      loader.start();
  
      frame = 0;
      //miscellaneous stuff
  
      synchronized(images){
          while (images.isEmpty()){
              images.wait();
          }
      }
  
      this.setPrefferedSize(new Dimension(800,800));
  }
  
  @Override
  public void paintComponent(Graphics g){
      super.paintComponent(g)
  
      g.drawImage(images.get(frame), 0, 0, 800, 800, null);
  }
  </code></pre>
  
  <p>my Loader thread looks like this:</p>
  
  <pre><code>//Loader.java
  String dir;
  MyPanel caller;
  
  public Loader(String dir, MyPanel caller){
      this.dir = dir;
      this.caller = caller;
  }
  
  @Override
  public void run(){
      File dirFile = new File(dir);
      File[] files = dirFile.listFiles();
      Arrays.sort(files);
  
      for (File f : files) {
          try {
              synchronized (caller.images) {
                  BufferedImage buffImage = ImageIO.read(f);
                  caller.images.add(buffImage);
                  caller.images.notifyAll();
              }
          } catch (IOException e) {
          }
      }
  }
  </code></pre>
  
  <p>I have verified that execution passes through <code>notifyAll()</code> several times (usually >20) before the calling thread wakes up and displays the image in the frame.  I have also verified that the images object is in fact the same object as the one being waited on.  I have attempted adding a <code>yield()</code>, but that did not help.  why does the call to <code>notifyAll()</code> not wake the waiting thread immediately?</p>