private void block(){
  Thread t=Thread.currentThread();
  int i=0;
synchronized (this) {
    if (waitingThreads == null) {
      if (waitingThread == null) {
        waitingThread=t;
      }
 else {
        waitingThreads=new ArrayList<>();
        waitingThreads.add(waitingThread);
        waitingThreads.add(t);
        i=1;
        waitingThread=null;
      }
    }
 else {
      i=waitingThreads.size();
      waitingThreads.add(t);
    }
  }
  while (!finished) {
    try {
      t.wait(500);
    }
 catch (    Exception e) {
      Thread.yield();
    }
  }
synchronized (this) {
    Thread.interrupted();
    if (waitingThread == t) {
      waitingThread=null;
    }
    if (waitingThreads != null) {
      waitingThreads.remove(i);
    }
  }
}

private void block ( ) { Thread t = Thread . currentThread ( ) ; int i = 0 ; synchronized ( this ) { if ( waitingThreads == null ) { if ( waitingThread == null ) { waitingThread = t ; } else { waitingThreads = new ArrayList < > ( ) ; waitingThreads . add ( waitingThread ) ; waitingThreads . add ( t ) ; i = 1 ; waitingThread = null ; } } else { i = waitingThreads . size ( ) ; waitingThreads . add ( t ) ; } } while ( ! finished ) { try { t . wait ( 500 ) ; } catch ( Exception e ) { Thread . yield ( ) ; } } synchronized ( this ) { Thread . interrupted ( ) ; if ( waitingThread == t ) { waitingThread = null ; } if ( waitingThreads != null ) { waitingThreads . remove ( i ) ; } } }
blocks this thread until the image is finished
