public static void completeBackgroundTasks(long timeoutMillis){
  boolean fifoEmpty=false;
  boolean asyncThreadsCompleted=false;
  long absTimeout=System.currentTimeMillis() + timeoutMillis;
  while (System.currentTimeMillis() < absTimeout) {
synchronized (fifo) {
      fifoEmpty=fifo.size() == 0;
    }
synchronized (JGoogleAnalyticsTracker.class) {
      asyncThreadsCompleted=asyncThreadsRunning == 0;
    }
    if (fifoEmpty && asyncThreadsCompleted)     break;
    try {
      Thread.sleep(100);
    }
 catch (    InterruptedException e) {
      break;
    }
  }
}

public static void completeBackgroundTasks ( long timeoutMillis ) { boolean fifoEmpty = false ; boolean asyncThreadsCompleted = false ; long absTimeout = System . currentTimeMillis ( ) + timeoutMillis ; while ( System . currentTimeMillis ( ) < absTimeout ) { synchronized ( fifo ) { fifoEmpty = fifo . size ( ) == 0 ; } synchronized ( JGoogleAnalyticsTracker . class ) { asyncThreadsCompleted = asyncThreadsRunning == 0 ; } if ( fifoEmpty && asyncThreadsCompleted ) break ; try { Thread . sleep ( 100 ) ; } catch ( InterruptedException e ) { break ; } } }
wait for background tasks to complete . < p > this works in queued and asynchronous mode .
