question: 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 ; } } }
target:  Wait for background tasks to complete. <p> This works in queued and asynchronous mode.