code: 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;
              }
          }
      }
docs: Wait for background tasks to complete.
  <p>
  This works in queued and asynchronous mode.
  
  @param timeoutMillis  The maximum number of milliseconds to wait.