0
public class Signal2NoiseRatio
{
    public ImagePlus SingleSNR(ImagePlus imagePlus) throws InterruptedException
    {

        new Thread()
        { 
          @Override public void run() 
          { 
              for (int i = 0; i <= 1; i++)
              { 
                  System.out.println("in queue"+i);
              }

              synchronized( this ) 
              { 
                  this.notify(); 
              }
            } 
        }.start();


        synchronized (this) 
        {
        this.wait();
        }


        return imagePlusToProcess;
    }
}

notify() does not reach wait().

what's wrong here?

It is essential for me that both synchonized methods in this one method are implemented.

the main thread perform a frame which presents an image in it. Is it possible that the wait() method leads the frame to a white window?

hagem
  • 189
  • 3
  • 16

2 Answers2

2

this in the SingleSNR method and this in the overridden run method are not the same object (inside run, this refers to the anonymous subclass of Thread). You need to make sure you are notifying the same object you wait for, which is available as Signal2NoiseRatio.this:

      @Override public void run() 
      { 
          for (int i = 0; i <= 1; i++)
          { 
              System.out.println("in queue"+i);
          }

          synchronized( Signal2NoiseRatio.this ) 
          { 
              Signal2NoiseRatio.this.notify(); 
          }
        } 
Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
0

two "this"s are not the same, one is Signal2NoiseRatio, one is the Thread

andy
  • 1,336
  • 9
  • 23