private synchronized static void startBackgroundThread ( ) { if ( backgroundThread == null ) { backgroundThreadMayRun = true ; backgroundThread = new Thread ( asyncThreadGroup , "AnalyticsBackgroundThread" ) { public void run ( ) { logger . debug ( "AnalyticsBackgroundThread started" ) ; while ( backgroundThreadMayRun ) { try { String url = null ; synchronized ( fifo ) { if ( fifo . isEmpty ( ) ) { fifo . wait ( ) ; } if ( ! fifo . isEmpty ( ) ) { // Get a reference to the oldest element in the FIFO, but leave it in the FIFO until it is processed. url = fifo . getFirst ( ) ; } } if ( url != null ) { try { dispatchRequest ( url ) ; } finally { // Now that we have completed the HTTP request to GA, remove the element from the FIFO. synchronized ( fifo ) { fifo . removeFirst ( ) ; } } } } catch ( Exception e ) { logger . error ( "Got exception from dispatch thread" , e ) ; } } } } ; // Don't prevent the application from terminating. // Use completeBackgroundTasks() before exit if you want to ensure that all pending GA requests are sent. backgroundThread . setDaemon ( true ) ; backgroundThread . start ( ) ; } }
If the background thread for queued mode is not running start it now .